{"@attributes":{"version":"2.0"},"channel":{"title":"DEV Community: Tim Jones","description":"The latest articles on DEV Community by Tim Jones (@timothydjones).","link":"https:\/\/dev.to\/timothydjones","image":{"url":"https:\/\/media2.dev.to\/dynamic\/image\/width=90,height=90,fit=cover,gravity=auto,format=auto\/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F557962%2F9e235317-6c46-4fc4-a1ce-5ac49c6ce52e.png","title":"DEV Community: Tim Jones","link":"https:\/\/dev.to\/timothydjones"},"language":"en","item":[{"title":"Install Tmux on Git for Windows","pubDate":"Tue, 07 Dec 2021 14:47:05 +0000","link":"https:\/\/dev.to\/timothydjones\/install-tmux-on-git-for-windows-1cf2","guid":"https:\/\/dev.to\/timothydjones\/install-tmux-on-git-for-windows-1cf2","description":"<p><a href=\"https:\/\/gitforwindows.org\/\">Git for Windows<\/a> is a special version of the <a href=\"https:\/\/www.msys2.org\/\">MSYS2<\/a> with some customizations for better integration with Windows. In particular, in my experience, MSYS2 with Git does not work properly with <a href=\"https:\/\/code.visualstudio.com\/\">Visual Studio Code<\/a>, while Git for Windows works perfectly without any tweaking. However, Git for Windows version of MSYS2 does not include many of the other tools that are available in the standard MSYS2 installation, including Tmux. Nevertheless, we can install Tmux from the MSYS2 repositories with a little bit of effort.<\/p>\n\n<p>Before making these changes, you should back up the Git for Windows installation directory, typically <code>C:\\Program Files\\Git<\/code>. You can simply copy this directory to another folder so that you have a backup in case something goes wrong in the update process.<\/p>\n\n<p>Newer packages from the MSYS2 repositories &lt;<a href=\"http:\/\/repo.msys2.org\/msys\/x86_64\/\">http:\/\/repo.msys2.org\/msys\/x86_64\/<\/a>&gt; use Facebook's new <a href=\"http:\/\/facebook.github.io\/zstd\/\">Zstandard compression<\/a>. These files have <code>.zst<\/code> file extension. To decompress them, you will need to download the <a href=\"https:\/\/sourceforge.net\/projects\/zstd-for-windows\/files\/\">zstd for Windows<\/a> native Windows tool. Place the tool in a directory in your path, such as <code>C:\\Windows<\/code>, since you will be running this tool from the Windows Command Prompt.<\/p>\n\n<p>In addition, you will also need a tool capable of extracting <code>tar<\/code> archives. Fortunately, the Git for Windows installation includes the <code>tar<\/code> utility as one of the standard tools. Or your can use a GUI tool such as <a href=\"https:\/\/www.7-zip.org\/\">7-Zip<\/a>, which supports this archive type.<\/p>\n\n<p>In addition to the Tmux executable itself, a few other files from the standard MSYS2 installation, particularly from the <a href=\"https:\/\/packages.msys2.org\/base\/libevent\"><code>libevent<\/code><\/a> library, are needed. So we will download several packages from the <a href=\"http:\/\/repo.msys2.org\/msys\/x86_64\/\">MSYS2 repositories<\/a>. Since packages are updated frequently, the version numbers of the packages may change. Accordingly, in the list below, the version numbers are represented by <code>x.y.z-p<\/code>. You will need to replace these with the current\/latest version number.<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight shell\"><code>libevent-x.y.z-p-x86_64.pkg.tar.xz\ntmux-x.y.z-p-x86_64.pkg.tar.zst\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>To decompress the Zstandard compressed files, run the native Windows <code>zstd<\/code> tool (see above) at a <strong>Windows Command Prompt<\/strong> with the <code>-d<\/code> (\"decompress\") option:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight shell\"><code>zstd <span class=\"nt\">-d<\/span> tmux-x.y.z-p-x86_64.pkg.tar.zst\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>This will give you two <code>tar<\/code> archives that can then be extracted using the <code>tar<\/code> tool at the <strong>Git Bash prompt<\/strong>:<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight shell\"><code><span class=\"nb\">tar<\/span> <span class=\"nt\">-xvf<\/span> tmux-x.y.z-p-x86_64.pkg.tar\n<span class=\"nb\">tar<\/span> <span class=\"nt\">-Jxvf<\/span> libevent-x.y.z-p-x86_64.pkg.tar.xz\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>Since you have updated the files in the running Git Bash session, you will need to close the Git Bash prompt and open a new session. (Note: Tmux <em>only<\/em> works with the <a href=\"https:\/\/mintty.github.io\/\">MinTTY<\/a> version of Git Bash (<code>git-bash.exe<\/code>). If you usually use the native <code>bash.exe<\/code> or <code>git-cmd.exe<\/code> Git prompts, you'll get the error <code>open terminal failed: not a terminal<\/code> when trying to run Tmux.) <\/p>\n\n<p>In the new Git Bash instance, launch a new Tmux session normally by running <code>tmux<\/code>. You should see the usual Tmux status bar and you'll be able to use the normal Tmux functions and keyboard shortcuts. Likewise, if you run Git Bash (again, the MinTTY version) in <a href=\"https:\/\/conemu.github.io\/\">ConEmu<\/a>, Tmux works just fine in it, as well.<\/p>\n\n","category":["linux","productivity","devops","tutorial"]},{"title":"Understanding the Fundamental Django Framework Paradigms","pubDate":"Mon, 11 Jan 2021 18:05:22 +0000","link":"https:\/\/dev.to\/timothydjones\/understanding-the-fundamental-django-framework-paradigms-12mi","guid":"https:\/\/dev.to\/timothydjones\/understanding-the-fundamental-django-framework-paradigms-12mi","description":"<p>Undoubtedly, the <a href=\"https:\/\/djangoproject.com\/\">Django web framework<\/a> is powerful and flexible. At the same time, for beginners, it can be daunting to learn. I tried learning it several times by following \"beginners\" tutorials and, while successfully completing them, in the sense of having a working application, I never felt like the concepts clicked.<\/p>\n\n<p>It turns out that Django has <em>two<\/em> fundamental paradigms that you <strong>must<\/strong> understand (conceptualize) and internalize to learn and successfully use it:<\/p>\n\n<ol>\n<li>The difference between \"projects\" (sometimes referred to as \"sites\") and \"apps\" in Django; and<\/li>\n<li>The HTTP request\/response cycle in Django and how data flows through the various files to display a page.\nLet's look at each in more detail to see how they underpin the whole of Django, along with some additional references that you can explore.<\/li>\n<\/ol>\n\n<h2>\n  \n  \n  Projects and Apps in Django\n<\/h2>\n\n<p>The source of the confusion between <em>projects<\/em> and <em>apps<\/em> usually arises from the simple fact that what we often think of as an \"application\" (the overall, \"big picture\" package) is what Django refers to as the <strong>project<\/strong>. It is the <strong>top-level container<\/strong> for all of the work that makes up overall web application or site. Accordingly, sometimes, you'll also see the terms \"project\" and \"site\" used interchangeably in Django discussions.<\/p>\n\n<p>Perhaps the best way to think about it is that, most often, immediately after you set up your Python virtual environment, the very first thing you do when developing with Django is to create a <strong>project<\/strong>. For example, if your new application\/site name is <em>my_web_site<\/em>, you would do something like this (I'm using Linux):<br>\n<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight shell\"><code><span class=\"nb\">mkdir <\/span>my_web_site\n<span class=\"nb\">cd <\/span>my_web_site\npython3 <span class=\"nt\">-m<\/span> venv .venv\n<span class=\"nb\">source<\/span> .venv\/bin\/activate\npip3 <span class=\"nb\">install <\/span>django\ndjango-admin startproject my_web_site <span class=\"nb\">.<\/span>\n<\/code><\/pre>\n\n<\/div>\n\n\n\n<p>Note that the last line with the <strong><code>startproject<\/code><\/strong> command has <code>.<\/code> at the end, which tells <code>django-admin<\/code> to create the files in the current directory, <code>my_web_site<\/code>, instead of creating a new directory.<\/p>\n\n<p>By comparison, <strong>apps<\/strong> in Django's terminology are simply the ways that your project is <em>logically<\/em> subdivided and it provides <em>modularity<\/em> to the project. For example, if you were building an ecommerce site, you might have separate apps for <em>products<\/em>, <em>customers<\/em>, <em>orders<\/em>, <em>shopping carts<\/em>, etc. Django will place each of the apps into a separate subdirectory under your top-level directory.<\/p>\n\n<h2>\n  \n  \n  HTTP Request\/Response Cycle\n<\/h2>\n\n<p>First, don't be put off by some of the terms here. Essentially, this simply refers to how data flows through Django when someone interacts with a page, such as clicking a link or entering data into a form and pressing a <em>Submit<\/em> button and having Django process the data. <a href=\"https:\/\/en.m.wikipedia.org\/wiki\/Hypertext_Transfer_Protocol\">HTTP<\/a> is the \"language\" that web applications (and all of the WWW) speak. The <strong>request<\/strong> is the data the comes into Django and the <strong>response<\/strong> is the data that Django sends out after processing the input request.<\/p>\n\n<p>The basic request\/response flow and the associated Django files are:<\/p>\n\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>+----------------+\n|      URLs      |\n|    urls.py     |\n+----------------+\n         | \n         |\n         |\n         V \n+----------------+\n|      View      |\n|  app\/views.py  |\n+----------------+\n         |  \n         |                         \n         |\n         V                        \n+-----------------+\n| Model (optional)|\n| app\/models.py   |\n+-----------------+ \n         |                         \n         |                         \n         |                         \n         V \n+-----------------+\n|    Template     |\n|  template.html  |\n+-----------------+\n<\/code><\/pre>\n\n<\/div>\n\n<p>First, Django checks the <em>project-level<\/em> <code>urls.py<\/code> file, which itself typically \"includes\" the contained (subordinate) <em>app-level<\/em> <code>urls.py<\/code> files, as well, for the <code>urlpatterns<\/code> list to find the <strong>routes<\/strong> that are used. These routes represent patterns (called <a href=\"https:\/\/en.m.wikipedia.org\/wiki\/Regular_expression\">regular expressions<\/a>, but you don't need to worry about that too much at the beginning) for the URLs of your site, such as <code>\/home<\/code>, <code>\/about<\/code>, etc. These routes tell Django what <strong>views<\/strong> then handle those particular routes.<\/p>\n\n<p>Subsequently, Django directs the request to the appropriate view in the particular app (remember the difference between projects and apps in Django!). Each app in Django will typically have several views. The views typically obtain the content for the page from database <strong>models<\/strong>. (In <em>very<\/em> simple sites, such as static web sites, like a blog, you may not have a database.)<\/p>\n\n<p>Finally, Django takes <strong>templates<\/strong>, which <em>may<\/em> be shared among\/across apps, and combines the content with the styling and layout and, typically, some basic logic in the templates to render (build) the actual page for display. Templates provide benefits like allowing you to have standard menus, headers, and footers for your pages without re-creating them for each page.<\/p>\n\n<p>When you starting out with Django, having <em>four<\/em> files to manage just to display one page may seem like a lot of overhead. However, after you get accustomed to the pattern and flow and understand the paradigm, you will recognize the power and flexibility that it provides.<\/p>\n\n<h2>\n  \n  \n  Going Further\n<\/h2>\n\n<p>If you are just getting started with the Django Framework, I <em>highly<\/em> recommend <a href=\"http:\/\/leanpub.com\/djangoforbeginners\"><em>Django for Beginners<\/em><\/a> by <a href=\"https:\/\/wsvincent.com\/\">William S. Vincent<\/a>. The book goes through five projects in detail in such a way that you repeat key elements until they are clear and natural.<\/p>\n\n<p>Finally, the <a href=\"https:\/\/docs.djangoproject.com\/en\/3.1\/\">Django documentation<\/a> itself is excellent. It requires some patience for newcomers, but working through the tutorial <strong>after<\/strong> you have done a couple of beginners' tutorials is recommended to solidify your understanding the core concepts.<\/p>\n\n<p>I hope that this will help you on your journey to learn Django. Post your comments and question below.<\/p>\n\n","category":["django","python","webdev","tutorial"]}]}}