<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Floyd A. Morgan Jr on Medium]]></title>
        <description><![CDATA[Stories by Floyd A. Morgan Jr on Medium]]></description>
        <link>https://medium.com/@gr1nch3?source=rss-62c153e8b7c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_vefECuGfgim4fvMWQwkTQ.jpeg</url>
            <title>Stories by Floyd A. Morgan Jr on Medium</title>
            <link>https://medium.com/@gr1nch3?source=rss-62c153e8b7c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 14:27:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gr1nch3/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Creating a Reusable Django app]]></title>
            <link>https://blog.devgenius.io/creating-a-reusable-django-app-448c9631a886?source=rss-62c153e8b7c------2</link>
            <guid isPermaLink="false">https://medium.com/p/448c9631a886</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[packaging]]></category>
            <category><![CDATA[package]]></category>
            <category><![CDATA[pypi]]></category>
            <dc:creator><![CDATA[Floyd A. Morgan Jr]]></dc:creator>
            <pubDate>Sun, 25 Sep 2022 16:04:28 GMT</pubDate>
            <atom:updated>2022-09-27T07:59:54.195Z</atom:updated>
            <content:encoded><![CDATA[<p>Django Versatility does not stop at creating APIs or Impressive Web apps, We can also create packages from the apps within our Django Projects. In this article, we’ll be creating a package, uploading it to test.pypi and looking at how to use that package with other projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*xdk_hsbIJPcVVtuxz_DeHw.png" /></figure><h3>How Reusable?</h3><p>Before We begin, it is crucial to understand how the package we intend to create will work in the projects of others. Will our package gives functions to the project, or will it work as a standalone and interact with the database? Is my package going to need data from the project? Will my package pass data to the template? Etc. Answering these questions can help you better grasp how to structure your package.</p><h3>Creating your Package</h3><p>We’ll be using <a href="https://github.com/gr1nch3/django_memo.git">This repo</a> (also below) to create our package. It’s a simple memo app that allows users to save and check memos if it’s a task.</p><p><a href="https://github.com/gr1nch3/django_memo.git">GitHub - gr1nch3/django_memo: A simple django memo application</a></p><p>The project structure should be like this:</p><pre>django_memo<br>  |_django_memo<br>  |_memo<br>  |_theme<br>  |_manage.py</pre><p>The first step is to move the app we want to turn into a package to another folder, you can copy or cut it to the folder. You should pick a meaningful name for the folder, since it’s what your package will be referenced by. I’ll name mine django-memo. Outside that folder, we will create a virtual environment.(make sure your package and its virtual environment are in a separate workspace or folder</p><pre># first<br>python3 -m venv my-env<br># second<br>source my-env/bin/activate # macos/linux<br>my-env/scripts/activate.bat # windows</pre><p>Next is to install twine and setuptools, we’ll use them to build our package and test it.</p><pre>pip install twine setuptools</pre><h4>Extras</h4><p>In the folder you moved your app to(django-memo in my case), we are going to add the following files that will configure and build your package: <strong>setup.cfg, LICENSE, pyproject.toml, README.md </strong>and <strong>MANIFEST.in </strong>.</p><p><strong>pyproject.toml</strong></p><p>Add the following to your <strong>pyproject.toml </strong>file, and make sure the setuptools version matches the one you’ve installed.</p><pre>[build-system]<br>requires = [&#39;setuptools &gt;= 65.3.0&#39;, &#39;wheel&#39;]<br>build-backend = &#39;setuptools.build_meta:__legacy__&#39;</pre><p><strong>setup.cfg</strong></p><p>This file contains the metadata for <strong>PyPI </strong>and other requirements for your package. Make sure to check the requirements for your package version and set accordingly.</p><pre>[metadata]<br>name = django-memo<br>version = 1.2<br>description = A Django app to take and manage memo<br>readme = &quot;README.md&quot;<br>long_description = file: README.md <br>long_description_content_type=text/markdown<br>url = <a href="https://www.example.com/">https://www.example.com/</a><br>author = gr1nch3<br>author_email = example<a href="/service/mailto:lloydm763@gmail.com">@gmail.com</a><br>license = MIT License<br>classifiers =<br>    Environment :: Web Environment<br>    Framework :: Django<br>    Framework :: Django :: 4.0 # set your version<br>    Intended Audience :: Developers<br>    License :: OSI Approved :: MIT License<br>    Operating System :: OS Independent<br>    Programming Language :: Python<br>    Programming Language :: Python :: 3<br>    Programming Language :: Python :: 3 :: Only<br>    Programming Language :: Python :: 3.9<br>    Programming Language :: Python :: 3.10<br>    Topic :: Communications :: Chat</pre><pre>[options]<br>include_package_data = true<br>packages = find:<br>python_requires = &gt;=3.9<br>install_requires =<br>    Django &gt;= 4.0 # set your version</pre><p><strong>Note: </strong>the <strong>long_description </strong>by default is .rst, but .md works for me. The <strong>long_description </strong>and<strong> long_description_content_type </strong>needed to be configured like that to pass the <strong>twine</strong> check.</p><p><strong>README</strong></p><p>Your README file needs to be properly written in order to upload to pypi. It should also tell how to set up your package in a Django project.</p><pre>=====<br>Memo<br>=====</pre><pre>memo is a Django app to create memos and manage them</pre><pre>Detailed documentation is in the &quot;docs&quot; directory.</pre><pre>Quick start<br>-----------</pre><pre>1. Add &quot;memo&quot; to your INSTALLED_APPS setting like this::</pre><pre>INSTALLED_APPS = [<br>        ...<br>        &#39;memo&#39;,<br>  ]</pre><pre>2. Include the memo URLconf in your project urls.py like this::</pre><pre>path(&#39;memo/&#39;, include(&#39;memo.urls&#39;)),</pre><pre>3. Run ``python manage.py migrate`` to create the memo models.</pre><pre>4. Visit &#39;<a href="http://127.0.0.1:8000/memo/&#39;">http://127.0.0.1:8000/memo/&#39;</a> to check out your memos</pre><p><strong>LICENSE</strong></p><p>The License will contain the license for your package. We’ll use a MIT License</p><pre># MIT License</pre><pre>Copyright (c) [year] [your full name]</pre><pre>Permission is hereby granted, free of charge, to any person obtaining a copy<br>of this software and associated documentation files (the &quot;Software&quot;), to deal<br>in the Software without restriction, including without limitation the rights<br>to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<br>copies of the Software, and to permit persons to whom the Software is<br>furnished to do so, subject to the following conditions:</pre><pre>The above copyright notice and this permission notice shall be included in all<br>copies or substantial portions of the Software.</pre><pre>THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br>AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br>OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE<br>SOFTWARE.</pre><p><strong>MANIFEST.in</strong></p><p>The manifest will include other files, folders and templates that your package needs.</p><pre>include LICENSE<br>include README.md<br>recursive-include docs *</pre><p><strong>setup.py</strong></p><p>required to build the package</p><pre>from setuptools import setup</pre><pre>setup()</pre><p>After all the configurations, your package should look like this:</p><pre>...(workspace or folder)<br>  |_my-env<br>  |_django-memo<br>    |_memo<br>    |_LICENSE<br>    |_MANIFEST.in<br>    |_pyproject.toml<br>    |_README.md<br>    |_setup.cfg<br>    |_setup.py</pre><h3>Configuring our model</h3><p>In this section, we will configure our memo model to work with the projects it will be installed in. Since the memo model requires an abstract user. We’ll set it so that the package gets the user model from the settings. Just passing the user model to the settings (with AUTH_USER_MODEL) and accessing it as settings.AUTH_USER_MODEL for our memo model would pass the model as a string. So we’ll use the get_user_model() from django.contrib.auth. Our memo model structure will change to the following:</p><pre>from django.db import models</pre><pre>from django.contrib.auth import get_user_model # new</pre><pre>MemoUser = get_user_model() # new<br># Create your models here.</pre><pre># ---------------------------------------------------------------------------- #<br>#                           model of the memo detail                           #<br># ---------------------------------------------------------------------------- #</pre><pre>class Memo(models.Model):<br>                             # new<br>    user = models.ForeignKey(MemoUser, on_delete=models.CASCADE)<br>    title = models.CharField(max_length=100)<br>    memo = models.TextField(blank=True)<br>    created_at = models.DateTimeField(auto_now_add=True)<br>    updated_at = models.DateTimeField(auto_now=True)<br>    is_completed = models.BooleanField(default=False)</pre><pre>def __str__(self):<br>        return self.title</pre><pre>class Meta:<br>        db_table = &#39;memo&#39;<br>        verbose_name = &#39;Memo&#39;<br>        verbose_name_plural = &#39;Memos&#39;<br>        ordering = [&#39;-created_at&#39;]</pre><p>Note: If you were to pass a model to the package and use it as a foreign key, you can check out the code for the get_user_model() function, it works for passing other models as well, and you would only need to set it up in the settings.py.</p><h3>Testing our Package</h3><p>At this point, we’ve built and structured our app and have all files needed to turn it to a package.</p><h4>Build</h4><p>There are two ways we could create the dist folder that contains the package.</p><ol><li>We could use setuptools and run the command python setup.py sdist in the directory that contains our app and the packaging files, and we would get a build that would still pass the twine check .</li><li>We could also use the python build module’s python3 -m build command and get a similar result, and we would also get the wheel for the package</li></ol><h4>Test</h4><p>After you have created your dist folder, run the command twine check dist/* in the folder that contains the dist and you should see a message like this:</p><pre># if you used the first method<br>Checking dist/django-memo-1.2.tar.gz: PASSED</pre><pre># if you used the second method<br>Checking dist/django_memo-1.2-py3-none-any.whl: PASSED<br>Checking dist/django-memo-1.2.tar.gz: PASSED</pre><h4>Installing our Package</h4><p>To install our package locally in a project, we can run the following command: python -m pip install -U ./dist/django-memo-1.2.tar.gz .</p><h3>Uploading our Package</h3><p>We are going to upload our package to <a href="https://test.pypi.org/">test.PyPI</a>. Make sure to create an account. When done, go to account settings and add API token and create a token. Remember to copy your token someplace safe because you’ll be using it for uploads to test.PyPI. To upload to the real PyPI, you can use your credentials.</p><p>After creating the token, in your terminal, run the following command:</p><pre>python3 -m twine upload --repository testpypi dist/*</pre><p>You’ll be prompted for a username, and you should set the username value to __token__ . When you receive the prompt for a password, you add the token value you copied for the password. Results should be something similar:</p><pre>Uploading django_memo-1.2-py3-none-any.whl<br>100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 10.7/10.7 kB • 00:05 • 14.2 MB/s<br>Uploading django-memo-1.2.tar.gz<br>100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 9.6/9.6 kB • 00:00 • 9.6 MB/s</pre><pre>View at:<br><a href="https://test.pypi.org/project/django-memo/1.2/">https://test.pypi.org/project/django-memo/1.2/</a></pre><p>Congratulations! You Just created your first working package! If you follow the link from the result in your terminal, you should see your package on test.PyPI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qgHT6KbYWGPdatiTKM4XSw.png" /></figure><p>To view the package, check it out in this repo:</p><p><a href="https://github.com/gr1nch3/django-memo">GitHub - gr1nch3/django-memo</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=448c9631a886" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/creating-a-reusable-django-app-448c9631a886">Creating a Reusable Django app</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a Django Chat App (Without Django Channels)]]></title>
            <link>https://blog.devgenius.io/build-a-django-chat-app-without-django-channels-ef31838de64a?source=rss-62c153e8b7c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef31838de64a</guid>
            <category><![CDATA[tailwind-css]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[chat]]></category>
            <category><![CDATA[tailwind]]></category>
            <category><![CDATA[django-channels]]></category>
            <dc:creator><![CDATA[Floyd A. Morgan Jr]]></dc:creator>
            <pubDate>Sat, 20 Aug 2022 05:18:41 GMT</pubDate>
            <atom:updated>2022-08-29T20:04:24.095Z</atom:updated>
            <content:encoded><![CDATA[<h3>Django Chat App (Without Django Channels)</h3><p>Ever wondered what a Django chat application would be like without looking like it&#39;s based on discord or slack? Look no further! This article is about that thought being brought to life.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MRxB2HJ_rnNkAD220IPaVA.png" /></figure><p>I&#39;m assuming that you already have some knowledge in python and python Django. you might need a bit of tailwind knowledge if you want to modify the templates.</p><h3>Creating your Project</h3><p>create a folder called <strong>chat_django </strong>and navigate to the folder.</p><pre>mkdir chat_django &amp;&amp; cd chat_django</pre><p>For this Project, I will use a virtual environment.</p><pre># first<br>python3 -m venv env<br># second<br>source env/bin/activate # macos/linux<br>env/scripts/activate.bat # windows</pre><p>Next, install Django and <a href="https://github.com/django-crispy-forms/crispy-tailwind">cripsy_tailwind</a>. Crispy_tailwind is the tailwind version of bootstrap&#39;s cripsy_form used to style forms templates.</p><pre># install django<br>pip install Django<br># install crispy tailwind<br>pip install crispy-tailwind</pre><p>Now, we create our Django project.</p><pre>django-admin startproject django_chat &amp;&amp; cd django_chat</pre><p>Finally, create an app called <strong>chat.</strong></p><pre>python3 manage.py startapp chat</pre><h3>Setting up your Project</h3><p>We are going to make the following changes to our Project <strong>settings.py</strong></p><p>At the top of <strong>settings.py</strong> add import os.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*Z4UJCVUfF-zNrxptxyZbEw.png" /><figcaption>importing os to avoid PostSix error and get the theme path</figcaption></figure><p>To our <strong>INSTALLED_APPS = [] </strong>we&#39;ll add our custom app(chat), crispy forms, and crispy_tailwind.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*WE9RUCoXkcRICZLvE3n2aA.png" /></figure><p>We will be storing our static files/folders and templates in a folder called <strong>theme </strong>in our Django project directory.</p><pre>mkdir theme</pre><p>Your project folder should be something like this.</p><pre>chat_django<br>|_env<br>|_django_chat<br>  |_chat<br>  |_django_chat<br>  |_theme</pre><p>Go to your theme directory and create these three directories: <strong>src</strong>, <strong>templates</strong>, and <strong>static</strong></p><pre>cd theme &amp;&amp; mkdir src templates static</pre><p>We are going to make those folders accessible to Django since they are not in Django&#39;s default specified location.</p><p>in your <strong>settings.py </strong>add</p><pre>(BASE_DIR / &#39;themes/templates&#39;)</pre><p>to the <strong>TEMPLATES = [] </strong>like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iiWoPuYceHReoC0NIGKYTA.png" /></figure><p>In your <strong>settings.py </strong>add a <strong>STATICFILES_DIRS = []</strong>, this will tell Django which directory to read the static files from.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HxCuwzaOJeBTLfZEAvM7Mg.png" /></figure><p>we should be done with the <strong>settings.py</strong> for now.</p><h3>Chat app setup</h3><h4>Models</h4><p>In the <strong>models.py </strong>of our chat app, we are going to create a User model and a Message model.</p><ol><li>User Model: For our user model, we will be extending the <strong>AbstractUser </strong>from the <strong>django.contrib.auth.models</strong>. we are using the AbstractUser to get the auth benefits of the Django default User model. Our User model will have two fields. A username field, and an email field. Both will be unique.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ba-9KNtt0vwZHi7EpIEYIg.png" /></figure><p>2. Message Model: We&#39;ll use Django&#39;s default database model for the message model. We&#39;ll add a field for the sender and recipient which will be a reference to the <strong>UserProfile </strong>model. We&#39;ll also add a date field, to get the DateTime of the messages, and a is_read field to mark read messages</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SOQ8xqOi3wF5vetPGhVdSg.png" /></figure><p>Below the <strong>Message</strong> Model Meta class, we are going to add two functions:</p><ol><li><strong>get_all_messages(id_1, id_2): </strong>the function takes your primary key and the primary key of the person whose chat inbox you&#39;re opening and gets all the messages between you two and sorts them by date.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PcHXmdrxp32_dSuDHOi91Q.png" /></figure><p>2.<strong> get_message_list(u): </strong>takes your primary key, filters all messages that have either your primary key as the recipient or the sender, sorts them by username and date, and returns them while removing all other messages that do not have your primary key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9xWh2OrNrUX0JvCroDlqxA.png" /></figure><h4>Form</h4><p>Create a forms.py file in your <strong>chat</strong> app. Since we want users to signup for the app, we are going to create a custom signup form using <strong>UserCreationForm </strong>from the <strong>django.contrib.auth.forms. </strong>Because we are using crispy forms, the only fields we&#39;ll need to call in our Signup form will be the username and the email; the rest will be taken care of by the <strong>UserCreationForm. </strong>The form will add password fields and create a user with no admin or staff privileges.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AFTgctQnJQh_5fxcOpu0KQ.png" /></figure><h3>Views</h3><p>For the <strong>views.py, </strong>we will be creating four views :</p><ol><li><strong>signup view</strong>: sign up users</li><li><strong>messages list view</strong>: display all messages per user for the user logged in</li><li><strong>inbox view</strong>: a chat view between you and the other user</li><li><strong>users list view</strong>: to find new users to chat with</li></ol><p>Before we continue with creating the views, at the top of the views file, you need to import the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XHGM52qP9wRpThYfcPqvyA.png" /></figure><p>Now for the views:</p><blockquote>Signup View</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8AxmBsjNFpRH5oCcc5SgwQ.png" /><figcaption>A signup view that logs the user in after they signup</figcaption></figure><blockquote>Messages list view</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ceQ09UXmH2y8XVrkCJTg_Q.png" /><figcaption>The view has a LoginRequiredMixin, so authenticated users can only access it. Uses the get_message_list function from the message model</figcaption></figure><blockquote>Inbox view</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EJjOK2hv9EmjMyT1umr6Hg.png" /><figcaption>We are using a username in the url instead of the primary key. The above code gets the username for the view and also passes the user name to the post function</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HcByJ6M-ytGHQZmNvuIxPg.png" /><figcaption>Uses the get_all_messages and get_message_list to display messages in the chat and the messages list for the template</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uBpTQMMmQWncJrq6LEdyLg.png" /><figcaption>This function is called on to send a message in the chat.</figcaption></figure><blockquote>UserListsView</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aLPOTOzd3lGEL8KOR2Xd9w.png" /><figcaption>Display all users, excluding the user logged in</figcaption></figure><h4>Urls</h4><p>By default, Django apps are not created with a urls.py file, so you&#39;ll need to create it as you did with the forms.py. We are not going to build custom logout and login views, so we&#39;ll use Django&#39;s default <strong>LoginView</strong> and <strong>LogoutView</strong> views from the <strong>django.contrib.auth.views</strong>. All we&#39;ll need to do is to render a template or a url redirect (for LogoutView) for the default auth views.</p><p>In the urls.py add the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QsGYnPIDl7RabsxcrU83wA.png" /></figure><h3>Settings again?</h3><p>For our final tweak in settings.py we are going to add<strong>AUTH_USER_MODEL </strong>to specify which model we want to authenticate as the user model, we will also set the urls for the login and logout views and the redirect urls.</p><p>Add the following code under the STATICFILES_DIRS</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*Pj-iKuW8-4H03DR4-NRafw.png" /></figure><h3>Theme/Templates/static</h3><p>To set up the tailwind, static, and templates, check out this article:</p><p><a href="https://medium.com/@gr1nch3/django-tailwind-simplified-8befa0a281d4">Django + Tailwind Simplified</a></p><h4>crispy_tailwind</h4><p>To use crispy tailwind with our crispy forms, we need to add the following to the settings.py</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*0aW_Tu4O0J_huarx7TAXcA.png" /></figure><p>When done, the results should be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WlCmGSMDbJbe4ydQfeZJsQ.png" /></figure><p>Project git: <a href="https://github.com/gr1nch3/django_chat.git">https://github.com/gr1nch3/django_chat.git</a></p><p>Thanks for reading!</p><h3>Extras</h3><p>To continue the Project, you could add:</p><ol><li>unread messages count</li><li>a group chat feature</li><li>maybe a better template than I did</li><li>images or files upload within the chat</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef31838de64a" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/build-a-django-chat-app-without-django-channels-ef31838de64a">Build a Django Chat App (Without Django Channels)</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Django + Tailwind Simplified]]></title>
            <link>https://blog.devgenius.io/django-tailwind-simplified-8befa0a281d4?source=rss-62c153e8b7c------2</link>
            <guid isPermaLink="false">https://medium.com/p/8befa0a281d4</guid>
            <category><![CDATA[tailwind-css]]></category>
            <category><![CDATA[tailwind]]></category>
            <category><![CDATA[python-django-training]]></category>
            <category><![CDATA[django-framework]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Floyd A. Morgan Jr]]></dc:creator>
            <pubDate>Sat, 06 Aug 2022 17:57:54 GMT</pubDate>
            <atom:updated>2022-10-28T16:18:35.687Z</atom:updated>
            <content:encoded><![CDATA[<p>As we know, <strong>Django</strong> is a powerful web framework that allows you to handle both backend and frontend solutions, today we will be amplifying the frontend side of django with the powerful <strong>Tailwind css</strong> framework. I’m assuming you have some knowledge in django and tailwind.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x3G8saaBiHg1SRG_c-CKxw.png" /><figcaption>Our result at the end</figcaption></figure><h3>Let’s get started</h3><p>First create a new django project in your desired folder, for the sake of this post, my project name will be django_tailwind.</p><pre>django-admin startproject django_tailwind</pre><p>Now navigate to your project directory and create a folder called theme (You can name it whatever you want).</p><pre>mkdir theme</pre><p>To view our results properly, we are going to create a dummy app</p><pre>python manage.py startapp dummy</pre><p>now, your project structure should look like this:</p><pre>django_tailwind<br> |_django_tailwind<br> |_dummy<br> |_theme<br> |_manage.py</pre><p>What we are trying to achieve is the complete seperation of design and logic. We are going to add all of django static files and templates into the theme folder. To do that, let’s go the theme folder and initiate tailwind</p><pre>cd theme<br># generate an npm project<br>npm init -y<br># install tailwind<br>npm install -D tailwindcss<br># initiate tailwind<br>npx tailwindcss init</pre><p>Next we are going to create the <strong>templates</strong>,<strong> static </strong>and <strong>src </strong>folders in the theme folder.</p><pre>mkdir templates static src</pre><p>in your src folder, create a css file named input.css and add this to it</p><pre><a href="http://twitter.com/tailwind">@tailwind</a> base;<br><a href="http://twitter.com/tailwind">@tailwind</a> components;<br><a href="http://twitter.com/tailwind">@tailwind</a> utilities;</pre><p>your theme folder should look something like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/212/1*J8mEWyEsLs5qo-Ss8jy3Jg.png" /></figure><p>In your tailwind.config.js add this line to the content: []</p><pre>&quot;./templates/**/*.{html,js}&quot;</pre><p>You should have something like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/1*KEWbExDtAvh_XA03KPks3w.png" /></figure><p>In our package.json we are going to add the following npm scripts</p><pre>...<br>&quot;tailwind-watch&quot;: &quot;tailwindcss -i ./src/input.css -o ./static/css/output.css --watch&quot;,<br>&quot;tailwind-build&quot;: &quot;tailwindcss -i ./src/input.css -o ./static/css/output.css --minify&quot;<br>...</pre><p>Results should be</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*WKsTC6H6sU4RjGQRBEsQtg.png" /></figure><p>Next, in your template folder, we’ll create a base.html file, i’ll create mine in a layouts folder. When done, add this the follwing code to the base template(you can modify it afterwards to suit your needs).</p><pre>{% load static %}<br>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;</pre><pre>&lt;head&gt;<br>  &lt;meta charset=&quot;UTF-8&quot;&gt;<br>  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>  &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;ie=edge&quot;&gt;<br>  &lt;title&gt;Tailwind + Django&lt;/title&gt;</pre><pre>&lt;link rel=&quot;stylesheet&quot; href=&quot;{% static &#39;css/output.css&#39; %}&quot;&gt;<br> &lt;/head&gt;</pre><pre>&lt;body class=&quot;bg-grey-lightest font-serif leading-normal tracking-normal&quot;&gt;</pre><pre>&lt;div class=&quot;container mx-auto &quot;&gt;<br>   &lt;section class=&quot;flex items-center justify-center h-screen&quot;&gt;<br>    &lt;h1 class=&quot;text-5xl font-sans&quot;&gt;Django + Tailwind = ❤️&lt;/h1&gt;<br>   &lt;/section&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;/body&gt;</pre><pre>&lt;/html&gt;</pre><p>(Notice when calling the stylesheet we used {% static &#39;css/output.css&#39; %} ? this will be that file that the tailwind load the css to, and it will be used for all css purposes in the project like the normal stytles.css).</p><h3>Modifying the settings.py</h3><p>In our <strong>settings.py </strong>we are going to make some changes to ensure django serve the static files.</p><p>First we are going to add the <strong>dummy</strong> app we created to the installed apps</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/266/1*oYijs7BaqNeraBSA6FvHEQ.png" /></figure><p>Next, we should make sure django will read the templates from our theme folder. we’ll add (BASE_dir/&#39;theme/templates&#39;) to&#39;DIRS&#39;: [] like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*IIJnwXFt7pD3wbtW8NhcKg.png" /></figure><p>Now, using django mechanicsm to load static files, we are going to modify it to load static files from the theme folder. Frst at the top, add import os like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*nkOLD9TLgjE65RuluuAiig.png" /><figcaption>imported os to avoid PosixPath error when creating static_dir</figcaption></figure><p>Next we create a STATIC_DIRS to read static files from the theme folder</p><pre># add this<br>STATICFILES_DIRS = [os.path.join(BASE_DIR, &quot;theme/static/&quot;)]</pre><p>result should be like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*sdIoPYZqpMHH4DgHKFLrZQ.png" /></figure><h3>setting up the view from the ‘dummy’ app</h3><p>In your dummy app, go to views.py and add the following(remeber which directory your base template is located):</p><pre>#<em> Create your views here.</em></pre><pre>def index(request):<br>   return render(request, &#39;layouts/base.html&#39;)</pre><p>next, create a urls.py in your dummy app and add:</p><pre>from django.urls import path<br>from .views import index</pre><pre>urlpatterns = [<br>    path(&#39;&#39;, index, name=&#39;index&#39;),<br>]</pre><p>in your project main url file(located in the same directory as your settings.py), add the following:</p><pre>urlpatterns = [</pre><pre>path(&#39;admin/&#39;, admin.site.urls),</pre><pre>path(&#39;&#39;, include(&#39;dummy.urls&#39;)), # new</pre><pre>]</pre><p>this should complete the configurations,. Now run the command in the theme folder to load the tailwind css (src/input.css) to the css file in the static folder (static/css/output.css):</p><pre>npm run tailwind-watch</pre><p>to view the reuslts in your browser, run:</p><pre>python manage.py runserver</pre><p>P.s: make migrations if needed.</p><p>Results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mARkcp5iPtB-AOhePSX4jw.png" /></figure><p>project git: <a href="https://github.com/gr1nch3/django_tailwind.git">https://github.com/gr1nch3/django_tailwind.git</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8befa0a281d4" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/django-tailwind-simplified-8befa0a281d4">Django + Tailwind Simplified</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>