<?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 Tijesunimi Adebiyi on Medium]]></title>
        <description><![CDATA[Stories by Tijesunimi Adebiyi on Medium]]></description>
        <link>https://medium.com/@tijesu24?source=rss-3431a4612ead------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*VijBRDvl2tCKSlFw</url>
            <title>Stories by Tijesunimi Adebiyi on Medium</title>
            <link>https://medium.com/@tijesu24?source=rss-3431a4612ead------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 02:23:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tijesu24/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[NLP Analysis of The Vergecast Podcast Episode — “They Think They’re Building God”]]></title>
            <link>https://medium.com/@tijesu24/nlp-analysis-of-the-vergecast-podcast-episode-they-think-theyre-building-god-8b99d4107197?source=rss-3431a4612ead------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b99d4107197</guid>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[podcast]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-analysis]]></category>
            <dc:creator><![CDATA[Tijesunimi Adebiyi]]></dc:creator>
            <pubDate>Mon, 30 Sep 2024 13:09:50 GMT</pubDate>
            <atom:updated>2024-10-01T12:27:23.148Z</atom:updated>
            <content:encoded><![CDATA[<h3>NLP Analysis of The Vergecast Podcast Episode — “<strong>They Think They’re Building God”</strong></h3><p>In this article, I will be detailing my analysis of a Vergecast episode.</p><p>It will give insights into things like dialogue flow, speaker interactions and sentiment analysis. You can find the code <a href="https://github.com/tijesu24/Vergecast-NLP/">in my repository</a>.</p><h3>Getting the podcast episode transcript</h3><p>Thankfully, I did not have to transcribe the podcast myself because the transcript was already available on <a href="https://app.podscribe.ai/series/2516">Podscribe</a>. I downloaded the podcast transcript as a text file.</p><h3>Data Preparation</h3><p>The next thing to do was to convert the txt file into a format that was usable. The transcript already was segmented by speaker id. What I did was to convert the transcript to a dataframe with two columns — speaker, dialogue. I also had to concatenate consecutive dialogue entries where the speaker was the same.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*wQNT3xGDnrFn7XjFpRD1lQ.png" /><figcaption>Prepared dataset</figcaption></figure><h3>Speaker Analysis</h3><p>We need to have a general picture of how many words were spoken by each person.</p><p>There were three ways I used to calculate number of unique words</p><ul><li>The raw version without any processing</li><li>The lemmatized version</li><li>The lemmatized version where stop words and some low value words have been removed</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*X1NJCJj74aRqH_nGMDuamQ.png" /><figcaption>Counts of words spoken by each speaker</figcaption></figure><p>We notice that David says the most words in this episode followed by Kylie, Gabby and Addie. This makes sense since David Pierce is the host of the Vergecast.</p><p>We also need an idea of the most common words spoken by each speaker</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*BsPmJT9hAusp1FHo4mj6zg.png" /><figcaption>Word Cloud for David Pierce</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*ssMABECL7DDYp7kFMLNvUA.png" /><figcaption>Word Cloud for Kylie Robinson</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*y5c_8ZL8nHFts0SBptco9A.png" /><figcaption>Word Cloud for Addie Robertson</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*y6VK3VzFq4xOSsRZ0KS6KA.png" /><figcaption>Word Cloud for Gabby DelVal</figcaption></figure><p>We can see that “right” and “yeah” are some of the most common words among speakers. We also have an idea about the important keywords being discussed.</p><ul><li>Trump, Government, Tiktok, China, Crypto, trials, AI, OpenAI, congress, Google</li></ul><h3>Dialogue Flow Analysis</h3><p>I performed a flow analysis to see who was talking to whom and how long they were talking. The results of this can be shown using an interaction matrix and network graph</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*CCeNsTJCfJGhmaJKfwlSGQ.png" /><figcaption>Interaction matrix represented as a heat map</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1019/1*SGZRsdJafwyMr65s6ECpXw.png" /><figcaption>Showing interactions using a network graph</figcaption></figure><p>From these visualisations, we can see two sets of interactions. One between David and Kylie and another between David, Gabby and Addie. The majority of the podcast takes place in the interaction between David and Kylie because they have the highest number of interactions.</p><h3>Topic Analysis</h3><p>Using basic word frequency analysis,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/187/1*52uSgoXNxfDmpZsV4MRClA.png" /><figcaption>Word frequency analysis</figcaption></figure><p>We can see that the majority of the podcast is focused on AI and OpenAI.</p><p>If we perform word frequency analysis by speaker</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*BrJDdj-yxa-Rqzs2s1KIlg.png" /><figcaption>Word frequency analysis by speaker</figcaption></figure><p>We can see that the interaction between David and Kylie was focused on OpenAI, while the interaction between David, Addie and Robertson was focused more on legal issues with keywords like Trump, TikTok, China, Google.</p><p><strong>Using Latent Dirichlet Allocation (LDA)</strong></p><p>LDA does not give any new information.</p><pre>Identified Topics:<br><br>Topic 1: 0.013*&quot;going&quot; + 0.009*&quot;lot&quot; + 0.009*&quot;first&quot; + 0.008*&quot;trump&quot; + <br>0.008*&quot;sort&quot; + 0.007*&quot;way&quot; + 0.007*&quot;wan&quot; + 0.006*&quot;good&quot; + 0.006*&quot;people&quot; + <br>0.006*&quot;get&quot;<br><br>Topic 2: 0.008*&quot;hard&quot; + 0.008*&quot;people&quot; + 0.007*&quot;things&quot; + 0.006*&quot;everybody&quot; + <br>0.006*&quot;oh&quot; + 0.006*&quot;asked&quot; + 0.006*&quot;well&quot; + 0.005*&quot;three&quot; + 0.005*&quot;believe&quot; +<br> 0.005*&quot;reasoning&quot;<br><br>Topic 3: 0.011*&quot;openai&quot; + 0.009*&quot;also&quot; + 0.009*&quot;way&quot; + 0.007*&quot;company&quot; + <br>0.007*&quot;well&quot; + 0.007*&quot;people&quot; + 0.006*&quot;back&quot; + 0.006*&quot;basically&quot; + <br>0.006*&quot;google&quot; + 0.005*&quot;tiktok&quot;<br><br>Topic 4: 0.011*&quot;okay&quot; + 0.011*&quot;people&quot; + 0.010*&quot;time&quot; + 0.009*&quot;things&quot; + <br>0.008*&quot;tiktok&quot; + 0.008*&quot;actually&quot; + 0.007*&quot;feel&quot; + 0.007*&quot;god&quot; + 0.007*&quot;back&quot; +<br> 0.006*&quot;building&quot;<br><br>Topic 5: 0.010*&quot;ai&quot; + 0.010*&quot;something&quot; + 0.009*&quot;make&quot; + 0.008*&quot;stuff&quot; + <br>0.007*&quot;feel&quot; + 0.007*&quot;us&quot; + 0.007*&quot;openai&quot; + 0.007*&quot;google&quot; + 0.006*&quot;case&quot; + <br>0.006*&quot;got&quot;</pre><h3>Using <strong>Non-Negative Matrix Factorization</strong></h3><p>NMF also does not give much new information. Topics 2 and 3 show that the podcast talks about court case(s)involving Google, TikTok and the government (DOJ).</p><pre>Topic #1:<br>people, tiktok, crypto, bunch, actually, well, talking, get, would, little<br><br>Topic #2:<br>ai, gonna, openai, model, something, reasoning, get, building, thinking, <br>answer<br><br>Topic #3:<br>people, necessarily, threat, access, google, case, seems, tiktok, coins, doj<br><br>Topic #4:<br>trump, platform, tiktoks, china, government, owned, gave, <br>national, pages, financial<br><br>Topic #5:<br>user, gi, agents, researcher, insurance, helpful, asked, thought, <br>genuinely, medical<br><br>Topic #6:<br>back, feel, everybody, go, openai, going, wanna, stuff, seems, tech<br><br>Topic #7:<br>trump, persons, kept, government, borrowing, talking, crypto, university, <br>platform, sued<br><br>Topic #8:<br>trump, china, government, threat, look, chinese, gotten, announce, owned, <br>part<br><br>Topic #9:<br>back, wanna, everybody, feel, two, real, new, gonna, path, big<br><br>Topic #10:<br>hard, something, make, google, lot, sort, use, things, week, last</pre><h3>LLM Summary of Transcript</h3><p>Feeding the transcript into a Large Language Model (LLM) yields the following summarisation result.</p><h4>AI Discussion with Kylie Robinson and David Pierce</h4><ul><li>OpenAI’s new model <strong>O1</strong> introduced as a “reasoning model”</li><li>Concerns over anthropomorphization of AI models</li><li>Ethical issues raised about O1’s potential for manipulation</li><li>Speculation on OpenAI’s motivations and future direction</li><li>Emergence of competitive AI models like Anthropic’s Claude 3.5</li></ul><h4>Legal and Regulatory Issues with Gabby DelVal and Addie Robertson</h4><p><strong>TikTok Ban Controversy</strong></p><ul><li>Ongoing legal battle over potential TikTok ban in the US</li><li>Government cites national security concerns related to Chinese ownership</li><li>Lack of transparency regarding specific evidence against TikTok</li></ul><p><strong>Donald Trump’s Crypto Venture</strong></p><ul><li>Introduction of <strong>World Liberty Financial</strong> platform</li><li>Focus on “debanked” individuals and underserved communities</li><li>Parallels drawn to Trump University controversy</li><li>Growing influence of crypto community in politics</li></ul><p><strong>Google Ad Tech Trial</strong></p><ul><li>DOJ alleges Google’s anti-competitive practices in ad tech industry</li><li>Similarities to previous Google search trial noted</li><li>Challenges in conveying complex case details to broader audience</li></ul><p>This summary agrees with the Topic Analysis I have performed albeit providing more information than could be gotten from Topic Analysis alone.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b99d4107197" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Create a Blog Site Using Django: Part 4 — Integrating a rich text editor and media manager]]></title>
            <link>https://blog.stackademic.com/how-to-create-a-blog-site-using-django-part-4-integrating-a-rich-text-editor-and-media-manager-de22dfca8724?source=rss-3431a4612ead------2</link>
            <guid isPermaLink="false">https://medium.com/p/de22dfca8724</guid>
            <category><![CDATA[fullstack-web-development]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[backend-development]]></category>
            <dc:creator><![CDATA[Tijesunimi Adebiyi]]></dc:creator>
            <pubDate>Tue, 02 Jul 2024 08:17:40 GMT</pubDate>
            <atom:updated>2024-07-15T00:41:24.846Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Create a Blog Site Using Django</h3><h4>Part 4 — Integrating a rich text editor and media manager</h4><p>While managing my mentor’s WordPress site, there were two features I noticed that made content creation easier: a rich text editor that made it easy to create blog posts and a media manager that made image selection simple. In our Django blog application, we’ll implement these features using CKEditor 5 and django-filer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Eb8gplGUnrLMaKnElzCavQ.png" /><figcaption>django-filer and CKEditor in action</figcaption></figure><h4>Step 1: Set up CKEditor 5</h4><p>Adapted from the <a href="https://pypi.org/project/django-ckeditor-5/">official documentation</a></p><h4>1. Install the Library</h4><p>First, install the CKEditor 5 package:</p><pre>pip install django-ckeditor-5</pre><h4>2. Add CKEditor to Your Settings</h4><p>Next, add django_ckeditor_5 to the INSTALLED_APPS in your settings.py file:</p><pre># django_blog/settings.py<br><br>INSTALLED_APPS = [<br>    ...<br>    &#39;django_ckeditor_5&#39;,<br>]</pre><h4>2. Add CKEditor to Your Settings</h4><p>Next, add django_ckeditor_5 to the INSTALLED_APPS in your settings.py file:</p><pre>STATIC_URL = &#39;/static/&#39;<br>MEDIA_URL = &#39;/media/&#39;<br>MEDIA_ROOT = os.path.join(BASE_DIR, &#39;media&#39;)<br><br>customColorPalette = [<br>        {<br>            &#39;color&#39;: &#39;hsl(4, 90%, 58%)&#39;,<br>            &#39;label&#39;: &#39;Red&#39;<br>        },<br>        {<br>            &#39;color&#39;: &#39;hsl(340, 82%, 52%)&#39;,<br>            &#39;label&#39;: &#39;Pink&#39;<br>        },<br>        {<br>            &#39;color&#39;: &#39;hsl(291, 64%, 42%)&#39;,<br>            &#39;label&#39;: &#39;Purple&#39;<br>        },<br>        {<br>            &#39;color&#39;: &#39;hsl(262, 52%, 47%)&#39;,<br>            &#39;label&#39;: &#39;Deep Purple&#39;<br>        },<br>        {<br>            &#39;color&#39;: &#39;hsl(231, 48%, 48%)&#39;,<br>            &#39;label&#39;: &#39;Indigo&#39;<br>        },<br>        {<br>            &#39;color&#39;: &#39;hsl(207, 90%, 54%)&#39;,<br>            &#39;label&#39;: &#39;Blue&#39;<br>        },<br>    ]<br>  CKEDITOR_5_CONFIGS = {<br>    &#39;default&#39;: {<br>        &#39;toolbar&#39;: [&#39;heading&#39;, &#39;|&#39;, &#39;bold&#39;, &#39;italic&#39;, &#39;link&#39;,<br>                    &#39;bulletedList&#39;, &#39;numberedList&#39;, &#39;blockQuote&#39;, &#39;imageUpload&#39;, ],<br>    },<br>    &#39;extends&#39;: {<br>        &#39;blockToolbar&#39;: [<br>            &#39;paragraph&#39;, &#39;heading1&#39;, &#39;heading2&#39;, &#39;heading3&#39;,<br>            &#39;|&#39;,<br>            &#39;bulletedList&#39;, &#39;numberedList&#39;,<br>            &#39;|&#39;,<br>            &#39;blockQuote&#39;,<br>        ],<br>        &#39;toolbar&#39;: [&#39;heading&#39;, &#39;|&#39;, &#39;outdent&#39;, &#39;indent&#39;, &#39;|&#39;, &#39;bold&#39;, &#39;italic&#39;, &#39;link&#39;, &#39;underline&#39;, &#39;strikethrough&#39;,<br>        &#39;code&#39;,&#39;subscript&#39;, &#39;superscript&#39;, &#39;highlight&#39;, &#39;|&#39;, &#39;codeBlock&#39;, &#39;sourceEditing&#39;, &#39;insertImage&#39;,<br>                    &#39;bulletedList&#39;, &#39;numberedList&#39;, &#39;todoList&#39;, &#39;|&#39;,  &#39;blockQuote&#39;, &#39;imageUpload&#39;, &#39;|&#39;,<br>                    &#39;fontSize&#39;, &#39;fontFamily&#39;, &#39;fontColor&#39;, &#39;fontBackgroundColor&#39;, &#39;mediaEmbed&#39;, &#39;removeFormat&#39;,<br>                    &#39;insertTable&#39;,],<br>        &#39;image&#39;: {<br>            &#39;toolbar&#39;: [&#39;imageTextAlternative&#39;, &#39;|&#39;, &#39;imageStyle:alignLeft&#39;,<br>                        &#39;imageStyle:alignRight&#39;, &#39;imageStyle:alignCenter&#39;, &#39;imageStyle:side&#39;,  &#39;|&#39;],<br>            &#39;styles&#39;: [<br>                &#39;full&#39;,<br>                &#39;side&#39;,<br>                &#39;alignLeft&#39;,<br>                &#39;alignRight&#39;,<br>                &#39;alignCenter&#39;,<br>            ]<br>        },<br>        &#39;table&#39;: {<br>            &#39;contentToolbar&#39;: [ &#39;tableColumn&#39;, &#39;tableRow&#39;, &#39;mergeTableCells&#39;,<br>            &#39;tableProperties&#39;, &#39;tableCellProperties&#39; ],<br>            &#39;tableProperties&#39;: {<br>                &#39;borderColors&#39;: customColorPalette,<br>                &#39;backgroundColors&#39;: customColorPalette<br>            },<br>            &#39;tableCellProperties&#39;: {<br>                &#39;borderColors&#39;: customColorPalette,<br>                &#39;backgroundColors&#39;: customColorPalette<br>            }<br>        },<br>        &#39;heading&#39; : {<br>            &#39;options&#39;: [<br>                { &#39;model&#39;: &#39;paragraph&#39;, &#39;title&#39;: &#39;Paragraph&#39;, &#39;class&#39;: &#39;ck-heading_paragraph&#39; },<br>                { &#39;model&#39;: &#39;heading1&#39;, &#39;view&#39;: &#39;h1&#39;, &#39;title&#39;: &#39;Heading 1&#39;, &#39;class&#39;: &#39;ck-heading_heading1&#39; },<br>                { &#39;model&#39;: &#39;heading2&#39;, &#39;view&#39;: &#39;h2&#39;, &#39;title&#39;: &#39;Heading 2&#39;, &#39;class&#39;: &#39;ck-heading_heading2&#39; },<br>                { &#39;model&#39;: &#39;heading3&#39;, &#39;view&#39;: &#39;h3&#39;, &#39;title&#39;: &#39;Heading 3&#39;, &#39;class&#39;: &#39;ck-heading_heading3&#39; }<br>            ]<br>        }<br>    },<br>    &#39;list&#39;: {<br>        &#39;properties&#39;: {<br>            &#39;styles&#39;: &#39;true&#39;,<br>            &#39;startIndex&#39;: &#39;true&#39;,<br>            &#39;reversed&#39;: &#39;true&#39;,<br>        }<br>    }<br>}<br>CKEDITOR_5_UPLOAD_FILE_TYPES = [&#39;jpeg&#39;, &#39;pdf&#39;, &#39;png&#39;, &#39;jpg&#39;]</pre><p>The code defines the URLs for serving static and media files, and sets the root directory for media files. It also configures CKEditor with a custom color palette and toolbars.</p><h4>4. Add CKEditor URLs</h4><p>Include CKEditor URLs in your urls.py file:</p><pre># blog/urls.py<br><br>from django.conf import settings<br>from django.conf.urls.static import static<br>from django.urls import include<br>...<br>urlpatterns += [<br>    path(&quot;ckeditor5/&quot;, include(&#39;django_ckeditor_5.urls&#39;)),<br>] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)</pre><h4>5. Update Your Models</h4><p>Adjust your models.py file to use CKEditor for the post content field:</p><pre># blog/models.py<br><br><br>from django_ckeditor_5.fields import CKEditor5Field<br><br>class Post(models.Model):<br>    ...<br><br>    content = CKEditor5Field(<br>        &#39;Text&#39;, config_name=&#39;extends&#39;, null=True, blank=True)</pre><h4>Step 2: Integrating the media manager (django-filer)</h4><p>Adapted from the <a href="https://django-filer.readthedocs.io/en/latest/installation.html">official documentation</a></p><h4>1. Install the Package</h4><p>Install django-filer:</p><pre>pip install django-filer</pre><h4>2. Add Filer to Your Settings</h4><p>Update your settings.py to include django-filer:</p><pre># django_blog/settings.py<br><br>INSTALLED_APPS = [<br>    ...<br>    &#39;easy_thumbnails&#39;,<br>    &#39;filer&#39;,<br>    ...<br>]<br><br>...<br>THUMBNAIL_PROCESSORS = (<br>    &#39;easy_thumbnails.processors.colorspace&#39;,<br>    &#39;easy_thumbnails.processors.autocrop&#39;,<br>    &#39;filer.thumbnail_processors.scale_and_crop_with_subject_location&#39;,<br>    &#39;easy_thumbnails.processors.filters&#39;,<br>)<br>FILER_CANONICAL_URL = &#39;uploads/&#39;</pre><h4>3. Add Filer URLs</h4><p>Include filer URLs in your urls.py:</p><pre># blog/urls.py<br><br>from django.urls import re_path<br>urlpatterns = [<br>    ...<br>    re_path(r&#39;^filer/&#39;, include(&#39;filer.urls&#39;)),<br>    ...<br>]</pre><h4>4. Update Your Models</h4><p>Adjust your models.py to use Filer for the cover image field:Change the cover_image field in the Post model so that the cover_images will be selected with the filer application.</p><pre># blog/models.py <br><br>from filer.fields.image import FilerImageField<br>class Post(models.Model):<br>    ...<br>    cover_image = FilerImageField(null=True, blank=True,<br>                  related_name=&quot;cover_image&quot;, on_delete=models.CASCADE)</pre><h4>5. Migrate Your Database</h4><p>Apply the changes to your database:</p><pre>python manage.py makemigrations<br>python manage.py migrate</pre><h3>Stackademic 🎓</h3><p>Thank you for reading until the end. Before you go:</p><ul><li>Please consider <strong>clapping</strong> and <strong>following</strong> the writer! 👏</li><li>Follow us <a href="https://twitter.com/stackademichq"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/stackademic"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/c/stackademic"><strong>YouTube</strong></a> | <a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a></li><li>Visit our other platforms: <a href="https://plainenglish.io/"><strong>In Plain English</strong></a> | <a href="https://cofeed.app/"><strong>CoFeed</strong></a> | <a href="https://differ.blog/"><strong>Differ</strong></a></li><li>More content at <a href="https://stackademic.com/"><strong>Stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de22dfca8724" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/how-to-create-a-blog-site-using-django-part-4-integrating-a-rich-text-editor-and-media-manager-de22dfca8724">How to Create a Blog Site Using Django: Part 4 — Integrating a rich text editor and media manager</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Create a Blog Site Using Django: Part 3 — Authentication (Login, Register, Forgot Password)]]></title>
            <link>https://medium.com/@tijesu24/how-to-create-a-blog-site-using-django-part-3-authentication-login-register-forgot-password-feefa9b7422f?source=rss-3431a4612ead------2</link>
            <guid isPermaLink="false">https://medium.com/p/feefa9b7422f</guid>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[full-stack]]></category>
            <dc:creator><![CDATA[Tijesunimi Adebiyi]]></dc:creator>
            <pubDate>Thu, 27 Jun 2024 07:23:03 GMT</pubDate>
            <atom:updated>2024-07-12T00:20:07.914Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Create a Blog Site Using Django: Part 3 — Authentication (Login, Register, Forgot Password)</h3><p>This is a continuation of my django blog series.</p><p>Whenever users sign up on our website, we want to be able to verify their emails. To do this, we will send a verification link to their mails and their accounts will only be activated after going to the link. Also, we need to enable password reset functionality. When a user forgets their password, they should have to provide the email address, and if an account exists with the address, a password reset link is sent to the mail.</p><h3>Step 1: Email verification</h3><p>To verify users’ emails, we need to send a verification link to their email addresses. We will use Gmail’s SMTP server for this</p><h4>Getting SMTP Credentials</h4><p>We need smtp email server access credentials from our email client (in our case, gmail) to place in our settings.py file</p><ol><li><strong>Generate an App Password</strong>: You should not use your main google account password. Google provides app passwords that you can assign to specific applications you build. To obtain the credentials, login to your Google account and generate an app password <a href="https://myaccount.google.com/u/2/apppasswords?rapt=AEjHL4NhMtCL4vyXGxYeoNO44OyN8aSLUUv7xMt9x_SNzhevzzCqQROZ-LZUZI5Cjn6hEoFfiVrq0jCu9T4BRDiR60wY8AosQ8AMQwtvjonGCK2PbvMivp0">here</a>. Make sure to copy the app password to a secure place.</li><li><strong>Store Credentials Securely</strong>: Instead of putting our sensitive email credentials in our settings.py file, we will be saving them as environmental variables. This is done for security reasons. When we upload our code to github, we don’t want just anyone having access to this sensitive information.</li></ol><h4>Setting Up Environment Variables</h4><ul><li>In your project root folder, create a file named .gitignore and within this file add the following line</li></ul><pre>.env</pre><p>.env will be the name of the file where we will store the credentials and putting the filename in the .gitignore file means that github will not upload the file and there is no risk that an external person will have access to the user credentials through github.</p><ul><li>Create a .env file in the project root folder and add your credentials in this format</li></ul><pre>EMAIL_USER = &quot;your_email@address.com&quot;<br>EMAIL_PASSWORD = &quot;your_password&quot;</pre><h4>Dotenv library</h4><p>To load environmental variables from the .env file, we will be using the python-dotenv library. Install it by running pip install python-dotenv . Then you can load the environmental variables by calling the load_dotenv() function.</p><pre>#django_blog/setting.py<br><br>import os<br>from dotenv import load_dotenv<br>load_dotenv()<br><br><br># email configs<br>EMAIL_BACKEND = &#39;django.core.mail.backends.smtp.EmailBackend&#39;<br>EMAIL_HOST = &#39;smtp.gmail.com&#39;<br>EMAIL_USE_TLS = True<br>EMAIL_PORT = 587<br>EMAIL_HOST_USER = str(os.getenv(&#39;EMAIL_USER&#39;))<br>EMAIL_HOST_PASSWORD = str(os.getenv(&#39;EMAIL_PASSWORD&#39;))</pre><h4>Registration token generation</h4><p>Create a token.py file and add the following code to generate tokens for account activation:</p><pre># blog/token.py<br><br>from django.contrib.auth.tokens import PasswordResetTokenGenerator  <br><br><br>class TokenGenerator(PasswordResetTokenGenerator):  <br>    def _make_hash_value(self, user, timestamp):  <br>        return (  <br>            str(user.pk) + str(timestamp) +<br>            str(user.is_active)<br>        )  <br>account_activation_token = TokenGenerator()    </pre><ul><li>In the views.py file, update your registration view to send an activation email:</li></ul><pre># blog/views.py<br><br>from django.contrib.sites.shortcuts import get_current_site<br>from django.template.loader import render_to_string<br>from django.utils.http import urlsafe_base64_encode<br>from django.utils.encoding import force_bytes<br>from django.core.mail import EmailMessage<br>from django.http import HttpResponse<br>from .token import account_activation_token  <br><br><br>def register(response):<br>    if response.method == &#39;POST&#39;:  <br>        form = RegisterForm(response.POST)  <br>        if form.is_valid():  <br>            # save form in the memory not in database  <br>            user = form.save(commit=False)  <br>            user.is_active = False  <br>            user.save()  <br>            # to get the domain of the current site  <br>            current_site = get_current_site(response)  <br>            mail_subject = &#39;Activation link has been sent to your email id&#39;  <br>            message = render_to_string(&#39;registration/account_activate_email.html&#39;, {  <br>                &#39;user&#39;: user,  <br>                &#39;domain&#39;: current_site.domain,  <br>                &#39;uid&#39;:urlsafe_base64_encode(force_bytes(user.pk)),  <br>                &#39;token&#39;:account_activation_token.make_token(user),  <br>            })  <br>            to_email = form.cleaned_data.get(&#39;email&#39;)  <br>            email = EmailMessage(  <br>                        mail_subject, message, to=[to_email]  <br>            )  <br>            email.send()  <br>            return HttpResponse(&#39;Please confirm your email address to complete the registration&#39;)  <br>    else:  <br>        form = RegisterForm()  <br>    return render(response, &#39;registration/register.html&#39;, {&#39;form&#39;: form})</pre><p>Create a file in templates directory to hold the activation mail</p><pre>&lt;!-- blog/templates/registration/account_activate_email.html --&gt;<br><br>{% autoescape off %}  <br>Hi {{ user.username }},  <br>Please click on the link to confirm your registration,  <br>http://{{ domain }}{% url &#39;activate&#39; uidb64=uid token=token %}  <br>{% endautoescape %}</pre><p>Create a view for the account activation page</p><pre># blog/views.py<br><br>from django.utils.encoding import force_bytes, force_str<br>from django.contrib.auth.models import User<br>from django.utils.http import urlsafe_base64_decode, urlsafe_base64_encode<br>from django.contrib import messages<br><br>def activate(request, uidb64, token):<br>    try:<br>        uid = force_str(urlsafe_base64_decode(uidb64))<br>        myuser = User.objects.get(pk=uid)<br>    except (TypeError, ValueError, OverflowError, User.DoesNotExist):<br>        myuser = None<br><br>    if myuser is not None and account_activation_token.check_token(myuser, token):<br>        myuser.is_active = True<br>        myuser.save()<br>        login(request, myuser)<br>        messages.success(request, &quot;Your account has been activated!&quot;)<br>        return redirect(&#39;login&#39;)<br>    else:<br>        return render(request, &#39;registration/activation_failed.html&#39;)</pre><p>Add a url path for the activation link</p><pre># blog/urls.py<br><br> <br>urlpatterns = [  <br>    .....  <br>  <br>    path(&#39;activate/(?P&lt;uidb64&gt;[0-9A-Za-z_\-]+)/(?P&lt;token&gt;[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/&#39;,  <br>        views.activate, name=&#39;activate&#39;),  <br>]  </pre><p>Create a file activate_failed.html</p><pre>The activation link was invalid, possibly because it has already been used or has expired.</pre><p>Now, when a new user registers an account, they will get an email with an activation link which will allow them to activate their account.</p><h3>Step 2: Password reset</h3><p>To allow users to reset their passwords, we need to create the necessary views and templates.</p><h4>Creating Password Reset Templates</h4><p>password_reset_email.html</p><pre>&lt;!-- blog/templates/registration/password_reset_email.html --&gt;<br><br>{% autoescape off %}<br>  <br>To initiate the password reset process for your {{ user.email }} Django Registration/Login App Account, click the link below:<br><br>    {{ protocol }}://{{ domain }}{% url &#39;password_reset_confirm&#39; uidb64=uid token=token %}<br><br>If clicking the link above doesn&#39;t work, please copy and paste the URL in a new browser window instead.<br><br>In case you have forgotten, your username is {{ user.username }}<br><br>Sincerely,<br>The Developer<br>{% endautoescape %}</pre><p>blog/templates/registration/password_reset_subject.txt</p><pre>Blog - Password Reset Request</pre><p>password_reset_confirm.html</p><pre>&lt;!-- blog/templates/registration/password_reset_confirm.html --&gt;<br><br>{% extends &quot;base.html&quot; %}<br>{% block title %}<br>    Password Reset<br>{% endblock title %}<br>{% block content %}<br>    &lt;div class=&quot;form-content my-3 p-3&quot;&gt;<br>        &lt;div class=&quot;container&quot;&gt;<br>            &lt;div class=&quot;row justify-content-center&quot;&gt;<br>                &lt;div class=&quot;col-lg-5&quot;&gt;<br>                    {% if validlink %}<br>                        &lt;div class=&quot;card shadow-lg border-0 rounded-lg mt-0 mb-3&quot;&gt;<br>                            &lt;div class=&quot;card-header justify-content-center&quot;&gt;<br>                                &lt;h3 class=&quot;font-weight-light my-4 text-center&quot;&gt;Reset Your Password&lt;/h3&gt;<br>                            &lt;/div&gt;<br>                            {% if form.errors %}<br>                                &lt;div class=&quot;alert alert-danger alert-dismissible&quot; role=&quot;alert&quot;&gt;<br>                                    &lt;div id=&quot;form_errors&quot;&gt;<br>                                        {% for key, value in form.errors.items %}&lt;strong&gt;{{ value }}&lt;/strong&gt;{% endfor %}<br>                                    &lt;/div&gt;<br>                                    &lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;alert&quot; aria-label=&quot;Close&quot;&gt;<br>                                        &lt;span aria-hidden=&quot;true&quot;&gt;&amp;times;&lt;/span&gt;<br>                                    &lt;/button&gt;<br>                                &lt;/div&gt;<br>                            {% endif %}<br>                            &lt;div class=&quot;card-body&quot;&gt;<br>                                &lt;form method=&quot;POST&quot;&gt;<br>                                    {% csrf_token %}<br>                                    &lt;div class=&quot;form-row&quot;&gt;<br>                                        &lt;div class=&quot;col-md-10 offset-md-1&quot;&gt;<br>                                            &lt;div class=&quot;form-group&quot;&gt;<br>                                                &lt;label class=&quot;small mb-1&quot; for=&quot;id_new_password1&quot;&gt;New Password&lt;/label&gt;<br>                                                &lt;input type=&quot;password&quot;<br>                                                       name=&quot;new_password1&quot;<br>                                                       autocomplete=&quot;new-password&quot;<br>                                                       class=&quot;form-control&quot;<br>                                                       required<br>                                                       id=&quot;id_new_password1&quot;<br>                                                       placeholder=&quot;Enter password&quot; /&gt;<br>                                                &lt;span&gt;&lt;/span&gt;<br>                                            &lt;/div&gt;<br>                                        &lt;/div&gt;<br>                                    &lt;/div&gt;<br>                                    &lt;div class=&quot;form-row&quot;&gt;<br>                                        &lt;div class=&quot;col-md-10 offset-md-1&quot;&gt;<br>                                            &lt;div class=&quot;form-group&quot;&gt;<br>                                                &lt;label class=&quot;small mb-1&quot; for=&quot;id_new_password2&quot;&gt;New Password Confirmation&lt;/label&gt;<br>                                                &lt;input type=&quot;password&quot;<br>                                                       name=&quot;new_password2&quot;<br>                                                       autocomplete=&quot;new-password&quot;<br>                                                       required<br>                                                       id=&quot;id_new_password2&quot;<br>                                                       class=&quot;form-control&quot;<br>                                                       placeholder=&quot;Confirm password&quot; /&gt;<br>                                            &lt;/div&gt;<br>                                        &lt;/div&gt;<br>                                    &lt;/div&gt;<br>                                    &lt;div class=&quot;form-row&quot;&gt;<br>                                        &lt;div class=&quot;col-md-10 offset-md-1&quot;&gt;<br>                                            &lt;div class=&quot;form-group mt-0 mb-1&quot;&gt;<br>                                                &lt;button type=&quot;submit&quot; class=&quot;col-md-12 btn btn-dark&quot; id=&quot;reset&quot;&gt;Reset Password&lt;/button&gt;<br>                                            &lt;/div&gt;<br>                                        &lt;/div&gt;<br>                                    &lt;/div&gt;<br>                                &lt;/form&gt;<br>                            &lt;/div&gt;<br>                        &lt;/div&gt;<br>                    {% else %}<br>                        &lt;div class=&quot;alert alert-warning&quot;&gt;<br>                            The password reset link was invalid, possibly because it has already been used.<br>                            Please request a new password reset.<br>                        &lt;/div&gt;<br>                    {% endif %}<br>                &lt;/div&gt;<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>    &lt;/div&gt;<br>{% endblock content %}</pre><p>password_reset.html</p><pre>&lt;!-- blog/templates/registration/password_reset.html  --&gt;<br><br>{% extends &quot;base.html&quot; %}<br>{% block content %}<br>    &lt;div class=&quot;form-content my-3 p-3&quot;&gt;<br>        &lt;div class=&quot;container&quot;&gt;<br>            &lt;div class=&quot;row justify-content-center&quot;&gt;<br>                &lt;div class=&quot;col-lg-5&quot;&gt;<br>                    &lt;div class=&quot;card shadow-lg border-0 rounded-lg mt-0 mb-3&quot;&gt;<br>                        &lt;div class=&quot;card-header justify-content-center&quot;&gt;<br>                            {% if messages %}<br>                                &lt;ul class=&quot;messages&quot;&gt;<br>                                    {% for message in messages %}<br>                                        &lt;li {% if message.tags %}class=&quot;{{ message.tags }}&quot;{% endif %}&gt;{{ message }}&lt;/li&gt;<br>                                    {% endfor %}<br>                                &lt;/ul&gt;<br>                            {% endif %}<br>                            &lt;div id=&quot;error_div&quot;&gt;&lt;/div&gt;<br>                            &lt;h3 class=&quot;font-weight-light my-4 text-center&quot;&gt;Forgot Password?&lt;/h3&gt;<br>                        &lt;/div&gt;<br>                        {% if form.errors %}<br>                            &lt;div class=&quot;alert alert-danger alert-dismissible&quot; role=&quot;alert&quot;&gt;<br>                                &lt;div id=&quot;form_errors&quot;&gt;<br>                                    {% for key, value in form.errors.items %}&lt;strong&gt;{{ value }}&lt;/strong&gt;{% endfor %}<br>                                &lt;/div&gt;<br>                                &lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;alert&quot; aria-label=&quot;Close&quot;&gt;<br>                                    &lt;span aria-hidden=&quot;true&quot;&gt;&amp;times;&lt;/span&gt;<br>                                &lt;/button&gt;<br>                            &lt;/div&gt;<br>                        {% endif %}<br>                        &lt;div class=&quot;card-body&quot;&gt;<br>                            &lt;form method=&quot;POST&quot;&gt;<br>                                {% csrf_token %}<br>                                &lt;div class=&quot;form-row&quot;&gt;<br>                                    &lt;div class=&quot;col-md-10 offset-md-1&quot;&gt;<br>                                        &lt;div class=&quot;form-group&quot;&gt;<br>                                            &lt;label class=&quot;small mb-1&quot; for=&quot;id_email&quot;&gt;Email&lt;/label&gt;<br>                                            &lt;input type=&quot;email&quot;<br>                                                   name=&quot;email&quot;<br>                                                   class=&quot;form-control&quot;<br>                                                   autocomplete=&quot;email&quot;<br>                                                   maxlength=&quot;254&quot;<br>                                                   required<br>                                                   id=&quot;id_email&quot;<br>                                                   placeholder=&quot;Enter email&quot;&gt;<br>                                        &lt;/div&gt;<br>                                    &lt;/div&gt;<br>                                &lt;/div&gt;<br>                                &lt;div class=&quot;form-row&quot;&gt;<br>                                    &lt;div class=&quot;col-md-10 offset-md-1&quot;&gt;<br>                                        &lt;div class=&quot;form-group mt-0 mb-1&quot;&gt;<br>                                            &lt;button type=&quot;submit&quot; class=&quot;col-md-12 btn btn-dark&quot;&gt;Submit&lt;/button&gt;<br>                                        &lt;/div&gt;<br>                                    &lt;/div&gt;<br>                                &lt;/div&gt;<br>                            &lt;/form&gt;<br>                        &lt;/div&gt;<br>                        &lt;div class=&quot;card-footer text-center&quot;&gt;<br>                            &lt;div class=&quot;small&quot;&gt;<br>                                &lt;a href=&quot;{% url &#39;register&#39; %}&quot;&gt;Create A New Account&lt;/a&gt;<br>                                &lt;br&gt;<br>                                &lt;br&gt;<br>                                &lt;a href=&quot;{% url &#39;login&#39; %}&quot;&gt;Back To Login&lt;/a&gt;<br>                                &lt;br&gt;<br>                            &lt;/div&gt;<br>                        &lt;/div&gt;<br>                    &lt;/div&gt;<br>                &lt;/div&gt;<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>    &lt;/div&gt;<br>{% endblock content %}</pre><p>password_reset_complete.html</p><pre>&lt;!-- blog/templates/registration/password_reset_complete.html --&gt;<br><br>{% extends &quot;base.html&quot; %}<br>{% block content %}<br>    &lt;div class=&quot;container my-3 p-3&quot;&gt;<br>        &lt;div class=&quot;row justify-content-center&quot;&gt;<br>            &lt;div class=&quot;col-lg-5&quot;&gt;<br>                &lt;div class=&quot;card shadow-lg border-0 rounded-lg mt-0 mb-3&quot;&gt;<br>                    &lt;div class=&quot;alert alert-info&quot;&gt;<br>                        Your password has been set. You may go ahead and &lt;a href=&quot;{% url &#39;login&#39; %}&quot;&gt;Login Here&lt;/a&gt;<br>                    &lt;/div&gt;<br>                &lt;/div&gt;<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>    &lt;/div&gt;<br>{% endblock content %}</pre><ul><li>Add the URL patterns to the urls file</li></ul><pre># blog/urls.py<br><br><br>from django.contrib.auth import views as auth_views<br><br>urlpatterns = [<br>    .......<br>    path(&#39;password-reset/&#39;, views.ResetPasswordView.as_view(), name=&#39;password_reset&#39;),<br>    path(&#39;password-reset-confirm/&lt;uidb64&gt;/&lt;token&gt;/&#39;,<br>         auth_views.PasswordResetConfirmView.as_view(<br>             template_name=&#39;registration/password_reset_confirm.html&#39;),<br>         name=&#39;password_reset_confirm&#39;),<br>    path(&#39;password-reset-complete/&#39;,<br>         auth_views.PasswordResetCompleteView.as_view(<br>             template_name=&#39;registration/password_reset_complete.html&#39;),<br>         name=&#39;password_reset_complete&#39;),<br><br>  ......<br>    path(&#39;&lt;slug:slug&gt;/&#39;, views.post_detail, name=&#39;post_detail&#39;),<br>]</pre><p>Update the forgot password link on the login template</p><pre><br>&lt;!-- blog/templates/registration/login.html --&gt;<br><br>....<br><br>&lt;p&gt;<br>    &lt;a href=&quot;{% url &#39;password_reset&#39; %}&quot;&gt;&lt;i&gt;Forgot Password?&lt;/i&gt;&lt;/a&gt;<br>&lt;/p&gt;<br><br><br>.....</pre><p>Then add this to the views.py file</p><pre># blog/views.py<br><br>from django.contrib.messages.views import SuccessMessageMixin<br>from django.contrib.auth.views import  PasswordResetView<br><br>class ResetPasswordView(SuccessMessageMixin, PasswordResetView):<br>    template_name = &#39;registration/password_reset.html&#39;<br>    email_template_name = &#39;registration/password_reset_email.html&#39;<br>    subject_template_name = &#39;registration/password_reset_subject.txt&#39;<br>    success_message = &quot;We&#39;ve emailed you instructions for setting your password, &quot; \<br>                      &quot;if an account exists with the email you entered. You should receive them shortly.&quot; \<br>                      &quot; If you don&#39;t receive an email, &quot; \<br>                      &quot;please make sure you&#39;ve entered the address you registered with, and check your spam folder.&quot;<br>    success_url = reverse_lazy(&#39;home&#39;)</pre><p>Create a script for displaying a feedback message that the password has been reset</p><pre>// blog/static/script.js<br><br>$(document).ready(function () {<br>    // Check if there are messages with ID &quot;password-reset-messages&quot;<br>    var messages = $(&#39;#password-reset-messages&#39;);<br>    if (messages.length &gt; 0) {<br>        // Extract the first message text<br>        var messageText = messages.find(&#39;li.message:first-child&#39;).text();<br><br>        // Create the Bootstrap alert element<br>        var alertHtml = &#39;&lt;div class=&quot;alert alert-success alert-dismissible fade show&quot; role=&quot;alert&quot;&gt;&#39;<br>            + messageText +<br>            &#39;&lt;button type=&quot;button&quot; class=&quot;btn-close&quot; data-bs-dismiss=&quot;alert&quot; aria-label=&quot;Close&quot;&gt;&lt;/button&gt;&#39;<br>            + &#39;&lt;/div&gt;&#39;;<br><br>        // Append the alert element to the div with ID &quot;alert-message&quot;<br>        $(&#39;#alert-message&#39;).html(alertHtml);<br><br>        // Optionally, remove the message after a delay<br>        setTimeout(function () {<br>            $(&#39;.alert&#39;).alert(&#39;close&#39;);<br>        }, 8000); // 5000 milliseconds (5 seconds) delay before closing the alert<br>    }<br><br><br>    // Optionally, remove the message after displaying the alert<br>    messages.remove();<br>});</pre><p>Import the script in the base.html file</p><pre>&lt;!-- blog/templates/base.html --&gt;<br><br>         .......<br><br>        &lt;script src=&quot;{% static &#39;script.js&#39; %}&quot;&gt;&lt;/script&gt;<br>    &lt;/body&gt;<br>&lt;/html&gt;</pre><p>If you look at the index.html file, you will notice this section at the end</p><pre>&lt;!-- blog/templates/index.html --&gt;<br><br><br>{% if messages %}<br>        &lt;ul id=&quot;password-reset-messages&quot; class=&quot;messages&quot; style=&quot;display: none;&quot;&gt;<br>            <br>            {% for message in messages %}<br>                &lt;li {% if message.tags %}class=&quot;message {{ message.tags }}&quot;{% endif %}&gt;{{ message }}&lt;/li&gt;<br>            {% endfor %}<br>        &lt;/ul&gt;<br>  {% endif %}</pre><p>This section allows any messages sent by the app to be added here and the Javascript code converts it to a modal so the user can see it.</p><h3>Conclusion</h3><p>In this part, we’ve successfully added email verification and password reset functionality to our Django blog site. In the next part, we will be adding a rich text editor to our blog.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=feefa9b7422f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Create a Blog Site Using Django: Part 2 — Admin and Authentication]]></title>
            <link>https://medium.com/@tijesu24/how-to-create-a-blog-site-using-django-part-2-admin-and-authentication-5fa97b59db9c?source=rss-3431a4612ead------2</link>
            <guid isPermaLink="false">https://medium.com/p/5fa97b59db9c</guid>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[full-stack]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Tijesunimi Adebiyi]]></dc:creator>
            <pubDate>Mon, 24 Jun 2024 23:17:05 GMT</pubDate>
            <atom:updated>2024-06-24T23:17:05.436Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Create a Blog Site Using Django: Part 2 — Admin and Authentication</h3><p>In this continuation of our blog creation series, we’ll set up an admin account and create an authentication system for our Django blog. We’ll walk you through creating an admin user, setting up user registration and login, and managing user permissions.</p><h3>Step 1: Create an Admin User</h3><p>First, we need to create a superuser who will have full access to the Django admin interface.</p><p>We are going to create an admin account and an authentication system.</p><ol><li><strong>Open your terminal</strong> and navigate to the project root folder.</li><li><strong>Run the following command</strong> to create a superuser:</li></ol><pre>python manage.py createsuperuser </pre><p>3. Enter a username, email address and password</p><pre>Username: johnsmith<br>Email address: mail@address.com<br>Password:<br>Password (again):</pre><p>You will get a prompt.</p><pre>Superuser created successfully.</pre><p>4. Start the server again:</p><pre>python manage.py runserver</pre><p>5. Go to 127.0.0.1:8000/admin in your browser and login to the admin account with the credentials you created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*v3B10avNN4ghpMaNtmtmjg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*ytDOKYIAq-0O6Tl26K1fzg.png" /><figcaption>Django Admin site</figcaption></figure><h3>Step 2: Creating an authentication system</h3><p>We need to allow users to register, log in, and manage their passwords. We’ll start by adding the necessary views and templates.</p><h4>Add Login and Registration Views</h4><p>Add the following functions to your views.py file in the blog app:</p><pre># blog/views.py<br>from .forms import RegisterForm, LoginForm<br>from django.shortcuts import render, redirect<br>from django.contrib.auth import login, logout<br>from django.contrib.auth.forms import PasswordChangeForm<br>from django.contrib.auth.views import PasswordChangeView<br>from django.urls import reverse_lazy<br><br><br>def register(response):<br>    if response.method == &#39;POST&#39;:<br>        form = RegisterForm(response.POST)<br>        if form.is_valid():<br>            form.save()<br>            return redirect(&#39;login&#39;)<br>    else:<br>        form = RegisterForm()<br>    return render(response, &#39;registration/register.html&#39;, {&#39;form&#39;: form})<br><br>    # login page<br><br><br>def user_login(request):<br>    if request.method == &#39;POST&#39;:<br>        form = LoginForm(request.POST)<br>        if form.is_valid():<br><br>            user = form.login(request)<br>            if user:<br>                login(request, user)<br>                return redirect(&#39;home&#39;)<br>    else:<br>        form = LoginForm()<br>    return render(request, &#39;registration/login.html&#39;, {&#39;form&#39;: form})<br><br><br>class ChangePasswordView(PasswordChangeView):<br>    form_class = PasswordChangeForm<br>    success_url = reverse_lazy(&#39;home&#39;)<br>    template_name = &#39;registration/change_password.html&#39;<br><br><br># logout page<br><br><br>def user_logout(request):<br>    logout(request)<br>    return redirect(&#39;home&#39;)<br><br><br>class ResetPasswordView(SuccessMessageMixin, PasswordResetView):<br>    template_name = &#39;registration/password_reset.html&#39;<br>    email_template_name = &#39;registration/password_reset_email.html&#39;<br>    subject_template_name = &#39;registration/password_reset_subject.txt&#39;<br>    success_message = &quot;We&#39;ve emailed you instructions for setting your password, &quot; \<br>                      &quot;if an account exists with the email you entered. You should receive them shortly.&quot; \<br>                      &quot; If you don&#39;t receive an email, &quot; \<br>                      &quot;please make sure you&#39;ve entered the address you registered with, and check your spam folder.&quot;<br>    success_url = reverse_lazy(&#39;home&#39;)</pre><h4>Create Authentication Templates</h4><p>Create the following templates:</p><p>blog/templates/registration/register.html</p><pre>{% extends &quot;base.html&quot; %}<br>{% block title %}Create an Account{% endblock %}<br>{% load crispy_forms_tags %}<br>{% block content %}<br>    &lt;div class=&quot;row justify-content-center&quot;&gt;<br>        &lt;div class=&quot;col-md-6 card mb-4  mt-3 top&quot;&gt;<br>            &lt;div class=&quot;card-body&quot;&gt;<br>                &lt;form method=&quot;post&quot; class=&quot;form-group&quot;&gt;<br>                    {% csrf_token %}<br>                    {{ form|crispy }}<br>                    &lt;button type=&quot;submit&quot; class=&quot;btn btn-success&quot;&gt;Register&lt;/button&gt;<br>                    &lt;a href=&quot;{% url &#39;login&#39; %}&quot;&gt;Already have account?&lt;/a&gt;<br>                &lt;/form&gt;<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>    &lt;/div&gt;<br>{% endblock %}</pre><p>blog/templates/registration/login.html</p><pre>{% extends &quot;base.html&quot; %}<br>{% block title %}Login Here{% endblock %}<br>{% load crispy_forms_tags %}<br>{% block content %}<br>    &lt;div class=&quot;row justify-content-center&quot;&gt;<br>        &lt;div class=&quot;col-md-6 card mb-4  mt-3 top&quot;&gt;<br>            &lt;div class=&quot;card-body&quot;&gt;<br>                &lt;form method=&quot;post&quot; class=&quot;from-group&quot;&gt;<br>                    {% csrf_token %}<br>                    {% crispy form %}<br>                    &lt;p&gt;<br>                        &lt;a href=&quot;&quot;&gt;&lt;i&gt;Forgot Password?&lt;/i&gt;&lt;/a&gt;<br>                    &lt;/p&gt;<br>                    &lt;p&gt;<br>                        Don&#39;t have an account? Create one &lt;a href=&quot;/register&quot;&gt;here&lt;/a&gt;<br>                    &lt;/p&gt;<br>                    &lt;!-- &lt;button type=&quot;submit&quot; class=&quot;btn btn-success&quot;&gt;Login&lt;/button&gt; --&gt;<br>                &lt;/form&gt;<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>    &lt;/div&gt;<br>{% endblock %}</pre><p>blog/templates/registration/password_reset.html</p><pre>{% extends &quot;base.html&quot; %}<br>{% block content %}<br>    &lt;div class=&quot;form-content my-3 p-3&quot;&gt;<br>        &lt;div class=&quot;container&quot;&gt;<br>            &lt;div class=&quot;row justify-content-center&quot;&gt;<br>                &lt;div class=&quot;col-lg-5&quot;&gt;<br>                    &lt;div class=&quot;card shadow-lg border-0 rounded-lg mt-0 mb-3&quot;&gt;<br>                        &lt;div class=&quot;card-header justify-content-center&quot;&gt;<br>                            {% if messages %}<br>                                &lt;ul class=&quot;messages&quot;&gt;<br>                                    {% for message in messages %}<br>                                        &lt;li {% if message.tags %}class=&quot;{{ message.tags }}&quot;{% endif %}&gt;{{ message }}&lt;/li&gt;<br>                                    {% endfor %}<br>                                &lt;/ul&gt;<br>                            {% endif %}<br>                            &lt;div id=&quot;error_div&quot;&gt;&lt;/div&gt;<br>                            &lt;h3 class=&quot;font-weight-light my-4 text-center&quot;&gt;Forgot Password?&lt;/h3&gt;<br>                        &lt;/div&gt;<br>                        {% if form.errors %}<br>                            &lt;div class=&quot;alert alert-danger alert-dismissible&quot; role=&quot;alert&quot;&gt;<br>                                &lt;div id=&quot;form_errors&quot;&gt;<br>                                    {% for key, value in form.errors.items %}&lt;strong&gt;{{ value }}&lt;/strong&gt;{% endfor %}<br>                                &lt;/div&gt;<br>                                &lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;alert&quot; aria-label=&quot;Close&quot;&gt;<br>                                    &lt;span aria-hidden=&quot;true&quot;&gt;&amp;times;&lt;/span&gt;<br>                                &lt;/button&gt;<br>                            &lt;/div&gt;<br>                        {% endif %}<br>                        &lt;div class=&quot;card-body&quot;&gt;<br>                            &lt;form method=&quot;POST&quot;&gt;<br>                                {% csrf_token %}<br>                                &lt;div class=&quot;form-row&quot;&gt;<br>                                    &lt;div class=&quot;col-md-10 offset-md-1&quot;&gt;<br>                                        &lt;div class=&quot;form-group&quot;&gt;<br>                                            &lt;label class=&quot;small mb-1&quot; for=&quot;id_email&quot;&gt;Email&lt;/label&gt;<br>                                            &lt;input type=&quot;email&quot;<br>                                                   name=&quot;email&quot;<br>                                                   class=&quot;form-control&quot;<br>                                                   autocomplete=&quot;email&quot;<br>                                                   maxlength=&quot;254&quot;<br>                                                   required<br>                                                   id=&quot;id_email&quot;<br>                                                   placeholder=&quot;Enter email&quot;&gt;<br>                                        &lt;/div&gt;<br>                                    &lt;/div&gt;<br>                                &lt;/div&gt;<br>                                &lt;div class=&quot;form-row&quot;&gt;<br>                                    &lt;div class=&quot;col-md-10 offset-md-1&quot;&gt;<br>                                        &lt;div class=&quot;form-group mt-0 mb-1&quot;&gt;<br>                                            &lt;button type=&quot;submit&quot; class=&quot;col-md-12 btn btn-dark&quot;&gt;Submit&lt;/button&gt;<br>                                        &lt;/div&gt;<br>                                    &lt;/div&gt;<br>                                &lt;/div&gt;<br>                            &lt;/form&gt;<br>                        &lt;/div&gt;<br>                        &lt;div class=&quot;card-footer text-center&quot;&gt;<br>                            &lt;div class=&quot;small&quot;&gt;<br>                                &lt;a href=&quot;{% url &#39;register&#39; %}&quot;&gt;Create A New Account&lt;/a&gt;<br>                                &lt;br&gt;<br>                                &lt;br&gt;<br>                                &lt;a href=&quot;{% url &#39;login&#39; %}&quot;&gt;Back To Login&lt;/a&gt;<br>                                &lt;br&gt;<br>                            &lt;/div&gt;<br>                        &lt;/div&gt;<br>                    &lt;/div&gt;<br>                &lt;/div&gt;<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>    &lt;/div&gt;<br>{% endblock content %}</pre><p>blog/templates/registration/change_password.html</p><pre>{% extends &#39;base.html&#39; %}<br>{% block title %}Change Password{% endblock %}<br>{% load crispy_forms_tags %}<br>{% block content %}<br>    &lt;div class=&quot;row justify-content-center&quot;&gt;<br>        &lt;div class=&quot;col-md-6 card mb-4  mt-3 top&quot;&gt;<br>            &lt;div class=&quot;text-dark&quot;&gt;Change password for {{ request.user.username }}&lt;/div&gt;<br>            &lt;div class=&quot;card-body&quot;&gt;<br>                &lt;form method=&quot;post&quot;&gt;<br>                    {% csrf_token %}<br>                    {{ form|crispy }}<br>                    &lt;button type=&quot;submit&quot; class=&quot;btn btn-success&quot;&gt;Change Password&lt;/button&gt;<br>                &lt;/form&gt;<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>    &lt;/div&gt;<br>{% endblock %}</pre><p>Update your base template with login and logout functionalities</p><pre>&lt;!--   blog/templates/base.html --&gt;<br>&lt;div class=&quot;collapse navbar-collapse&quot; id=&quot;navbarNavDropdown&quot;&gt;<br>      &lt;ul class=&quot;navbar-nav ms-auto&quot;&gt;<br>    ....<br>          {% if request.user.is_authenticated %}<br>              &lt;li class=&quot;nav-item text-black&quot;&gt;<br>                  &lt;a class=&quot;nav-link text-black font-weight-bold&quot;<br>                     href=&quot;{% url &#39;change_password&#39; %}&quot;&gt;Hello {{ request.user.username }}!!&lt;/a&gt;<br>              &lt;/li&gt;<br>              &lt;li class=&quot;nav-item text-black&quot;&gt;<br>                  &lt;a class=&quot;nav-link text-black font-weight-bold&quot;<br>                     href=&quot;{% url &#39;logout&#39; %}&quot;&gt;Logout&lt;/a&gt;<br>              &lt;/li&gt;<br>          {% else %}<br>              &lt;li class=&quot;nav-item text-black&quot;&gt;<br>                  &lt;a class=&quot;nav-link text-black font-weight-bold&quot; href=&quot;{% url &#39;login&#39; %}&quot;&gt;Login&lt;/a&gt;<br>              &lt;/li&gt;<br>              &lt;li class=&quot;nav-item text-black&quot;&gt;<br>                  &lt;a class=&quot;nav-link text-black font-weight-bold&quot;<br>                     href=&quot;{% url &#39;register&#39; %}&quot;&gt;Register&lt;/a&gt;<br>              &lt;/li&gt;<br>          {% endif %}<br>      &lt;/ul&gt;<br>&lt;/div&gt;</pre><h4>Add Login and Register forms</h4><p>Let’s update the forms.py file with our login and register forms</p><pre># blog/forms.py<br><br>from django.contrib.auth.forms import UserCreationForm<br>from django.contrib.auth.models import User<br>from crispy_forms.helper import FormHelper<br>from crispy_forms.layout import Submit<br>from django.contrib.auth import authenticate<br><br><br>class RegisterForm(UserCreationForm):<br>    email = forms.EmailField()<br><br>    class Meta:<br>        model = User<br>        fields = [&quot;username&quot;, &quot;email&quot;, &quot;password1&quot;, &quot;password2&quot;]<br><br><br>class LoginForm(forms.Form):<br>    username = forms.CharField()<br>    password = forms.CharField(widget=forms.PasswordInput)<br><br>    helper = FormHelper()<br>    helper.add_input(Submit(&#39;submit&#39;, &#39;Login&#39;, css_class=&#39;btn btn-success&#39;))<br>    helper.form_method = &#39;POST&#39;<br><br>    def clean(self):<br>        username = self.cleaned_data.get(&#39;username&#39;)<br>        password = self.cleaned_data.get(&#39;password&#39;)<br>        user = authenticate(username=username, password=password)<br>        if not user or not user.is_active:<br>            raise forms.ValidationError(<br>                &quot;Sorry, that login was invalid. Please try again.&quot;)<br>        return self.cleaned_data<br><br>    def login(self, request):<br>        username = self.cleaned_data.get(&#39;username&#39;)<br>        password = self.cleaned_data.get(&#39;password&#39;)<br>        user = authenticate(username=username, password=password)<br>        return user</pre><h4>Update the URL Patterns</h4><p>We need to update our URL configurations to include the views we just created.</p><pre># blog/urls.py<br><br>urlpatterns = [<br>    path(&#39;&#39;, views.PostList.as_view(), name=&#39;home&#39;),<br>    path(&#39;login/&#39;, views.user_login, name=&#39;login&#39;),<br>    path(&#39;logout/&#39;, views.user_logout, name=&#39;logout&#39;),<br>    path(&quot;register/&quot;, views.register, name=&quot;register&quot;),<br>    path(&#39;change-password/&#39;, views.ChangePasswordView.as_view(),<br>         name=&#39;change_password&#39;),<br>    path(&#39;&lt;slug:slug&gt;/&#39;, views.post_detail, name=&#39;post_detail&#39;),<br>]</pre><p>You can now create new users through the register form, login and logout from the site.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1nPZDCALZykqd1KlncvNGA.png" /><figcaption>Login page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7hpdNqCmTvfa-WcEasy5Ow.png" /><figcaption>Register page</figcaption></figure><h3>Step 3: Create user groups</h3><p><a href="https://docs.djangoproject.com/en/5.0/topics/auth/default/#groups">User groups</a> are used to categorise users and apply permissions to all members of the group at once. In our blog site, we will create a “Blog Managers” group that will give certain users permission to moderate comments and create or modify blog posts.</p><h4>Create a Management Command to Set Up the Blog Managers Group</h4><p>We’ll start by creating a management command to set up the “Blog Managers” group with the necessary permissions.</p><p><strong>Create the file</strong> blog/management/commands/create_blog_manager_group.py and add the following code:</p><pre>#blog/management/commands/create_blog_manager_group.py<br><br>from django.core.management.base import BaseCommand<br>from django.contrib.auth.models import Group, Permission, User<br>from django.apps import apps<br><br><br>class Command(BaseCommand):<br>    help = &#39;Create Blog Managers group with specific permissions&#39;<br><br>    def handle(self, *args, **kwargs):<br>        # Create the group<br>        group, created = Group.objects.get_or_create(name=&#39;Blog Managers&#39;)<br><br>        # List of permissions to add to the group<br>        permissions = [<br>            &#39;add_post&#39;,<br>            &#39;change_post&#39;,<br>            &#39;delete_post&#39;,<br>            &#39;publish_post&#39;,<br>            &#39;change_comment&#39;,<br>            &#39;delete_comment&#39;<br>        ]<br><br>        # Assign the permissions to the group<br>        for perm in permissions:<br>            permission = Permission.objects.get(codename=perm)<br>            group.permissions.add(permission)<br><br>        self.stdout.write(self.style.SUCCESS(<br>            &#39;Successfully created Blog Managers group and assigned permissions&#39;))</pre><p>2. Run the following command in the terminal to create the group and assign the permissions</p><pre>python manage.py create_blog_manager_group</pre><h3>Step 4: Assign new users to the blog manager group</h3><p>For our blog, new users can register an account but only the blog admin can add a user to the Blog Manager group. We can do this programmatically or through the admin site. We will do this through the admin site because that is most likely what your blog admin user will use.</p><h4>Modify the User Admin Interface</h4><p>We’ll customize the admin interface to include an action for adding users to the “Blog Managers” group.</p><ol><li>Add these lines to the admin.py file</li></ol><pre># blog/admin.py<br><br>from django.contrib.auth.models import User, Group<br>from django.contrib.auth.admin import UserAdmin as BaseUserAdmin<br>from django.contrib import messages<br><br>class UserAdmin(BaseUserAdmin):<br>    actions = [&quot;add_to_blog_managers&quot;]<br><br>    def add_to_blog_managers(modeladmin, request, queryset):<br>        # Get the Blog Managers group<br>        try:<br>            blog_managers_group = Group.objects.get(name=&#39;Blog Managers&#39;)<br>        except Group.DoesNotExist:<br>            messages.error(request, &#39;Blog Managers group does not exist.&#39;)<br>            return<br><br>        # Update selected users<br>        for user in queryset:<br>            user.groups.add(blog_managers_group)<br>            user.is_staff = True<br>            user.save()<br><br>        # Notify the admin user about the update<br>        messages.success(<br>            request, &#39;Selected users have been added to the Blog Managers group and granted staff status.&#39;)<br><br>    add_to_blog_managers.short_description = &quot;Make user a Blog Manager&quot;<br><br>    #  Add a custom method to check if a user is in the Blog Managers group<br>    def is_blog_manager(self, obj):<br>        return obj.groups.filter(name=&#39;Blog Managers&#39;).exists()<br>    is_blog_manager.boolean = True  # Display as a boolean icon<br>    is_blog_manager.short_description = &#39;Blog Manager&#39;  # Column name<br><br>    # Extend the list display to include the new method<br>    list_display = BaseUserAdmin.list_display + (&#39;is_blog_manager&#39;,)<br><br><br># Re-register UserAdmin<br>admin.site.unregister(User)<br>admin.site.register(User, UserAdmin)</pre><h4><strong>What does the code do?</strong></h4><p><strong>Define the Custom </strong><strong>UserAdmin Class</strong>:</p><ul><li>We extend the default UserAdmin class to include additional actions and display fields.</li></ul><pre>class UserAdmin(BaseUserAdmin):<br>    actions = [&quot;add_to_blog_managers&quot;]</pre><p><strong>Add Action to Make Users Blog Managers</strong>:</p><ul><li>We define an action called add_to_blog_managers which adds selected users to the &quot;Blog Managers&quot; group and grants them staff status.</li><li>This action first tries to get the “Blog Managers” group. If the group does not exist, it displays an error message.</li><li>For each selected user, it adds them to the group and sets their is_staff attribute to True, then saves the user.</li><li>After updating the users, it shows a success message.</li></ul><p><strong>Display Whether a User is a Blog Manager</strong>:</p><ul><li>We define a method is_blog_manager to check if a user is in the &quot;Blog Managers&quot; group.</li><li>This method returns True if the user is in the group, otherwise False. It is displayed as a boolean icon in the admin interface.</li><li>We set a short description for this method to name the column appropriately.</li></ul><p><strong>Extend the List Display</strong>:</p><ul><li>We extend the list_display attribute to include the is_blog_manager method, so it appears as a column in the user list.</li></ul><h4>How do you add a User to a Group?</h4><p>Follow these steps:</p><ul><li>Open the admin site (http://127.0.0.1:8000/admin/) and login to the admin account created earlier.</li><li>If you click the Users link on the sidebar, you should see a list of the users registered on the site</li><li>You can select the users you want to add to the group. From the action dropdown, select “Make user a Blog Manager” and apply the action.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1jZPmEAeoe79HUf_P3TtWg.png" /></figure><p>The selected users will now be part of the “Blog Managers” group and have the necessary permissions to create blog posts and manage comments.</p><h3>Conclusion</h3><p>By following these steps, you’ve set up user authentication and management in your Django blog application. Users can now register, log in and change their passwords. In the next part, we’ll cover email verification, password reset and integrating a rich-text editor.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5fa97b59db9c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Can you build a blog using Django?]]></title>
            <link>https://medium.com/@tijesu24/can-you-build-a-blog-using-django-5a5507c65381?source=rss-3431a4612ead------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a5507c65381</guid>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[django-admin]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Tijesunimi Adebiyi]]></dc:creator>
            <pubDate>Wed, 19 Jun 2024 23:27:15 GMT</pubDate>
            <atom:updated>2024-06-19T23:27:15.016Z</atom:updated>
            <content:encoded><![CDATA[<h3>Can I build a blog using Django?</h3><p>A couple of weeks ago, I started managing a WordPress site for a mentor and I had an idea</p><blockquote>“What if I build a blog/cms using Django…”</blockquote><p>This is a documentation of my process, including points where I hit a brick wall. Feel free to critique my methods and provide suggestions on what I could have done better</p><h3>Step 1: Setup</h3><h3><strong>Setting up our Django project</strong></h3><p>I am going to assume that you have Python and Django installed. However, if you don’t, you can follow the instructions <a href="https://docs.djangoproject.com/en/5.0/topics/install/#install-the-django-code">here</a>.</p><p>Once they are installed</p><p>· Open the command line/terminal</p><p>· Change the currently working directory to the folder where you want your project to be created</p><pre>cd path/to/folder</pre><p>·Run the following command</p><pre>django-admin startproject django-blog</pre><p>You can open your project folder in any IDE of choice (for me, that’s VSCode)</p><h3>Setup your environment (optional)</h3><p>Some people advise to use a different environment per project. There are multiple ways to manage a Python environment. The most common ways are using virtualenv/venv or using conda. You can find links to tutorials for each <a href="https://www.freecodecamp.org/news/how-to-setup-virtual-environments-in-python/">here</a> and <a href="https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html">here</a>.</p><h3>Step 2: First Django steps</h3><p><strong>Step 2.1</strong></p><ul><li>We need to create an application for our blog in the terminal. Make sure the current directory is the project directory and run the following command</li></ul><pre>python manage.py startapp blog</pre><p><em>Note: “blog” is the name of the application.</em></p><p>You should have a folder structure similar to this:</p><figure><img alt="Project folder structure" src="https://cdn-images-1.medium.com/max/294/1*WIKbXrH4cgidJ-3SYB6Elw.png" /><figcaption>Project folder structure</figcaption></figure><p><strong>Step 2.2</strong></p><ul><li>Add the the blog app to the list of installed apps in the “settings.py” file</li></ul><pre># settings.py<br><br>INSTALLED_APPS = [<br>    &#39;blog&#39;,<br><br>    ....<br>]</pre><p><strong>Step 2.3</strong></p><ul><li>Edit the urls file</li></ul><pre>#django_blog/urls.py<br><br>from django.contrib import admin<br>from django.urls import path, include<br><br>urlpatterns = [<br>    path(&#39;admin/&#39;, admin.site.urls),<br><br>    path(&quot;&quot;, include(&#39;blog.urls&#39;))<br><br>]</pre><p><strong>Step 2.4</strong></p><ul><li>Edit the models.py file in the app folder to add models for Blog Posts and Comments</li></ul><pre>from django.contrib.auth.models import User<br><br>STATUS = (<br>    (0, &quot;Draft&quot;),<br>    (1, &quot;Publish&quot;)<br>)<br><br><br>class Post(models.Model):<br>    title = models.CharField(max_length=200, unique=True)<br>    slug = models.SlugField(max_length=200, unique=True)<br>    author = models.ForeignKey(<br>        User, on_delete=models.CASCADE, related_name=&#39;blog_posts&#39;)<br>    updated_on = models.DateTimeField(auto_now=True)<br>    cover_image = models.ImageField(null=True, blank=True,<br>                                  related_name=&quot;cover_image&quot;, on_delete=models.CASCADE)<br>    content = models.TextField(null=True, blank=True)<br>    created_on = models.DateTimeField(auto_now_add=True)<br>    status = models.IntegerField(choices=STATUS, default=0)<br><br>    class Meta:<br>        ordering = [&#39;-created_on&#39;]<br>        permissions = [<br><br>            (&quot;publish_post&quot;, &quot;Can publish post&quot;),<br><br>        ]<br><br>    def __str__(self):<br>        return self.title<br><br>    def get_absolute_url(https://medium.com/self):<br>        from django.urls import reverse<br>        return reverse(&quot;post_detail&quot;, kwargs={&quot;slug&quot;: str(self.slug)})<br><br><br>class Comment(models.Model):<br>    post = models.ForeignKey(<br>        Post, on_delete=models.CASCADE, related_name=&#39;comments&#39;)<br>    created_on = models.DateTimeField(auto_now_add=True)<br>    name = models.CharField(max_length=80)<br>    email = models.EmailField()<br>    body = models.TextField()<br>    active = models.BooleanField(default=False)<br><br>    class Meta:<br>        ordering = [&#39;created_on&#39;]<br>        permissions = [<br><br>            (&quot;edit_comment_content&quot;, &quot;Can edit comment&quot;),<br><br><br>        ]<br><br>    def __str__(self) -&gt; str:<br>        # Use strftime to format the datetime object<br>        formatted_date = self.created_on.strftime(&#39;%B %d, %Y at %I:%M %p&#39;)<br>        return f&#39;Comment by {self.name} on {formatted_date}&#39;</pre><p>This code defines two models for a blog application using Django: Post and Comment.</p><p><strong>Post Model:</strong></p><ul><li>Represents a blog post with attributes like title, slug (unique URL identifier), author (linked to a Django user), update time (automatically updates on save), optional cover image, content, creation time (automatically set on creation), and a status field.</li><li>The STATUS constant defines choices for the status field, allowing posts to be marked as &quot;Draft&quot; or &quot;Publish&quot;.</li><li>The Meta class specifies that posts should be ordered by creation date with the most recent ones first (-created_on).</li><li>It also defines custom permissions: “publish_post” allows users to publish posts.</li><li>The __str__ method defines how a post object is represented as a string (using the title).</li><li>The get_absolute_url method generates the URL for viewing a post based on its slug.</li></ul><p><strong>Comment Model:</strong></p><ul><li>Represents a comment on a blog post with attributes like the associated post, creation time (automatically set on creation), commenter’s name, email, comment content, and an active flag (initially set to False).</li><li>The Meta class defines that comments should be ordered by creation date with the most recent ones first (-created_on).</li><li>It also defines a custom permission: “edit_comment_content” allows users to edit comment content.</li><li>The __str__ method defines how a comment object is represented as a string, including the commenter&#39;s name, formatted creation date, and a snippet of the comment content.</li></ul><p>Run the following in the terminal to create the models in the database</p><pre>python manage.py makemigrations</pre><pre>python manage.py migrate</pre><p><strong>Step 2.5</strong></p><ul><li>Django has an admin panel for creating and modifying model objects. It can be setup from the admin.py file in the blog app folder</li></ul><p>Add the follow code:</p><pre>#blog/admin.py<br><br>from django.contrib import admin<br>from .models import Post, Comment<br><br><br># Register your models here.<br><br>class CommentInline(admin.TabularInline):<br>    model = Comment<br>    readonly_fields = (&#39;post&#39;, &#39;created_on&#39;, &#39;name&#39;, &#39;email&#39;, &#39;body&#39;)<br><br><br>class PostAdmin(admin.ModelAdmin):<br><br>    list_display = (&#39;title&#39;, &#39;slug&#39;, &#39;status&#39;, &#39;created_on&#39;)<br>    list_filter = (&quot;status&quot;,)<br>    search_fields = [&#39;title&#39;, &#39;content&#39;]<br>    prepopulated_fields = {&#39;slug&#39;: (&#39;title&#39;,)}<br><br>    inlines = [CommentInline]<br><br>    def has_change_permission(self, request, obj=None):<br>        if obj and request.user.has_perm(&#39;blog.change_post&#39;):<br>            return True<br>        return super().has_change_permission(request, obj)<br><br>    def has_delete_permission(self, request, obj=None):<br>        if obj and request.user.has_perm(&#39;blog.delete_post&#39;):<br>            return True<br>        return super().has_delete_permission(request, obj)<br><br>    actions = [&#39;publish_publication&#39;, &quot;send_publication_to_drafts&quot;]<br><br>    def publish_publication(self, request, queryset):<br>        queryset.update(status=1)<br><br>    def send_publication_to_drafts(self, request, queryset):<br>        queryset.update(status=0)<br><br><br>admin.site.register(Post, PostAdmin)<br><br><br>@admin.register(Comment)<br>class CommentAdmin(admin.ModelAdmin):<br><br>    list_display = (&#39;name&#39;, &#39;body&#39;, &#39;post&#39;,  &#39;active&#39;)<br>    list_filter = (&#39;active&#39;, &#39;created_on&#39;, &#39;post&#39;)<br>    search_fields = (&#39;name&#39;, &#39;email&#39;, &#39;body&#39;, &#39;post&#39;)<br>    actions = [&#39;approve_comments&#39;, &#39;disapprove_comments&#39;]<br>    fields = (&#39;post&#39;, &#39;created_on&#39;, &#39;name&#39;, &#39;email&#39;,  &#39;body&#39;,  &#39;active&#39;)<br>    readonly_fields = (&#39;post&#39;, &#39;created_on&#39;, &#39;name&#39;, &#39;email&#39;, &#39;body&#39;)<br><br>    def approve_comments(self, request, queryset):<br>        queryset.update(active=True)<br><br>    def disapprove_comments(self, request, queryset):<br>        queryset.update(active=False)</pre><p>It registers two models, Post and Comment, and customizes their representation in the admin panel.</p><p>The PostAdmin class defines how blog posts are displayed and managed in the admin. It includes a list display to show post titles, slugs, status, and creation dates, filters for status, and search fields for titles and content. Slugs are automatically generated from titles using prepopulated_fields. Comments are displayed inline with posts, showing relevant fields as read-only. Custom permissions control whether a user can change or delete posts. Additionally, actions are provided to update the status of posts to published or draft.</p><p>The CommentAdmin class manages comments, with list displays and filters similar to PostAdmin. It includes actions to approve or disapprove comments, affecting their active status. Certain fields are set as read-only to prevent modification.</p><p><strong>Step 2.6</strong></p><ul><li>When viewing the comments in the admin panel, I wanted the comments list view to default to filtering for inactive comments. This code allows you to do that:</li></ul><pre><br>#blog/admin.py<br><br>from django.utils.translation import gettext_lazy as _<br><br>class CommentAdmin(admin.ModelAdmin):<br>    class CustomActiveFilter(admin.SimpleListFilter):<br>        title = _(&#39;Active&#39;)<br>        parameter_name = &#39;active&#39;<br><br>        def lookups(self, request, model_admin):<br>            return (<br>                (None, _(&#39;No&#39;)),<br>                (&#39;yes&#39;, _(&#39;Yes&#39;)),<br>                (&#39;all&#39;, _(&#39;All&#39;)),<br>            )<br><br>        def choices(self, cl):<br>            for lookup, title in self.lookup_choices:<br>                yield {<br>                    &#39;selected&#39;: self.value() == lookup,<br>                    &#39;query_string&#39;: cl.get_query_string({<br>                        self.parameter_name: lookup,<br>                    }, []),<br>                    &#39;display&#39;: title,<br>                }<br><br>        def queryset(self, request, queryset):<br>            if self.value() == &#39;yes&#39;:<br>                return queryset.filter(active=True)<br>            elif self.value() is None:<br>                return queryset.filter(active=False)<br><br>  #rest of class....</pre><p>In the lookups function, because the “No” option is first to be declared, it is automatically the default i.e. we filter for inactive comments (comments that are not yet allowed to be displayed on the blog post) by default.</p><h3>Step 3: Creating the application front-end</h3><p>We need to setup the urls for the app and the develop the front-end code.</p><p><strong>Step 3.1</strong></p><ul><li>Edit the forms.py in the blog app</li></ul><pre>#apps/forms.py<br><br>from .models import Comment<br>from django import forms<br><br>class CommentForm(forms.ModelForm):<br>    class Meta:<br>        model = Comment<br>        fields = (&#39;name&#39;, &#39;email&#39;, &#39;body&#39;)</pre><p>This creates a form for readers to leave comments on blog posts</p><p><strong>Step 3.2</strong></p><ul><li>Consider installing django-crispy-forms and crispy-bootstrap5 to make the forms look more aesthetically pleasing.</li></ul><p>Run this in the terminal</p><pre>pip install django-crispy-forms crispy-bootstrap5</pre><p>Add this to the settings.py file</p><pre>INSTALLED_APPS = (<br>    ...<br>    &quot;crispy_forms&quot;,<br>    &quot;crispy_bootstrap5&quot;,<br>    ...<br>)<br><br>CRISPY_ALLOWED_TEMPLATE_PACKS = &quot;bootstrap5&quot;<br><br>CRISPY_TEMPLATE_PACK = &quot;bootstrap5&quot;</pre><p><strong>Step 3.3</strong></p><ul><li>Edit views.py to define the views responsible for displaying the list of blog posts and the details of individual posts, along with their comments.</li></ul><pre>#blog/views.py<br><br>from django.shortcuts import render<br>from django.views import generic<br>from .models import Post<br>from .forms import CommentForm<br>from django.shortcuts import render, get_object_or_404<br><br># Create your views here.<br>class PostList(generic.ListView):<br>    queryset = Post.objects.filter(status=1).order_by(&#39;-created_on&#39;)<br>    template_name = &quot;index.html&quot;<br>    paginate_by = 6<br><br><br>def post_detail(request, slug):<br>    template_name = &#39;post_detail.html&#39;<br>    post = get_object_or_404(Post, slug=slug)<br>    comments = post.comments.filter(active=True)<br>    new_comment = None    # Comment posted<br>    if request.method == &#39;POST&#39;:<br>        comment_form = CommentForm(data=request.POST)<br>        if comment_form.is_valid():<br>            # Create Comment object but don&#39;t save to database yet<br>            new_comment = comment_form.save(commit=False)<br>            # Assign the current post to the comment<br>            new_comment.post = post<br>            # Save the comment to the database<br>            new_comment.save()<br>    else:<br>        comment_form = CommentForm()<br>    return render(request, template_name, {&#39;post&#39;: post,<br>                                           &#39;comments&#39;: comments,<br>                                           &#39;new_comment&#39;: new_comment,<br>                                           &#39;comment_form&#39;: comment_form})</pre><p><strong>PostList View</strong>: This is a class-based view that inherits from Django’s generic.ListView. It filters published posts (where status=1), orders them by creation date in descending order, and uses the index.html template to render the list. The posts are paginated, displaying six posts per page.</p><p><strong>post_detail View</strong>: This function-based view handles displaying the details of a single blog post. It retrieves the post based on the provided slug and fetches all active comments related to that post. If a POST request is made (typically when a comment form is submitted), it processes the form data, creates a new comment without saving it to the database immediately, assigns the current post to the comment, and then saves it. If the request is GET, it simply initializes an empty comment form. The view renders the post_detail.html template with the post, comments, and comment form data.</p><h3>Step 4: Setup static files</h3><p>We will need some static files in our web application.</p><p><strong>Step 4.1</strong></p><ul><li>Add these lines to the settings.py file</li></ul><pre>#django_blog/settings.py<br><br>import os<br>STATIC_URL = &#39;/static/&#39;<br>STATIC_ROOT = os.path.join(BASE_DIR, &#39;static&#39;)</pre><p><strong>Step 4.2</strong></p><ul><li>Create a static directory in the blog app directory i.e. blog/static</li><li>Create a css file named styles.css in the static directory i.e. blog/static/styles.css</li></ul><pre>/* blog/static/styles.css */<br><br>.hr {<br>    border-top: 2px solid #a3a3a3;<br>}<br><br>body {<br>    font-family: &quot;Roboto&quot;, sans-serif;<br>    font-size: 17px;<br>    background-color: #fdfdfd;<br>}<br>.shadow {<br>    box-shadow: 0 4px 2px -2px rgba(0, 0, 0, 0.1);<br>}<br>.btn-danger {<br>    color: #fff;<br>    background-color: #f00000;<br>    border-color: #dc281e;<br>}<br>.masthead {<br>    background: #3398E1;<br>    height: auto;<br>    padding-bottom: 15px;<br>    box-shadow: 0 16px 48px #E3E7EB;<br>    padding-top: 10px;<br>}<br><br>.card{<br>box-shadow: 0 16px 48px #E3E7EB;<br>}</pre><h3>Step 5: Create html templates</h3><p>Create a ‘templates’ folder in the blog app and then the following files</p><p><strong>blog/templates/base.html</strong></p><p>All other web pages will inherit from this</p><pre>{% load static %}<br>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>    &lt;head&gt;<br>        &lt;title&gt;My Blog&lt;/title&gt;<br>        &lt;link href=&quot;/static/django_ckeditor_5/dist/styles.css&quot;<br>              media=&quot;all&quot;<br>              rel=&quot;stylesheet&quot;&gt;<br>        &lt;link href=&quot;https://fonts.googleapis.com/css?family=Roboto:400,700&quot;<br>              rel=&quot;stylesheet&quot;&gt;<br>        &lt;meta name=&quot;google&quot; content=&quot;notranslate&quot; /&gt;<br>        &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot; /&gt;<br>        &lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css&quot;<br>              rel=&quot;stylesheet&quot;<br>              integrity=&quot;sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH&quot;<br>              crossorigin=&quot;anonymous&quot;&gt;<br>        &lt;link rel=&quot;stylesheet&quot; href=&quot;{% static &#39;styles.css&#39; %}&quot;&gt;<br>    &lt;/head&gt;<br>    &lt;body&gt;<br>        &lt;!-- Navigation --&gt;<br>        &lt;nav class=&quot;navbar navbar-expand-lg navbar-light bg-light shadow&quot;<br>             id=&quot;mainNav&quot;&gt;<br>            &lt;div class=&quot;container-fluid&quot;&gt;<br>                &lt;a class=&quot;navbar-brand&quot; href=&quot;{% url &#39;home&#39; %}&quot;&gt;Blog Title&lt;/a&gt;<br>                &lt;button class=&quot;navbar-toggler&quot;<br>                        type=&quot;button&quot;<br>                        data-bs-toggle=&quot;collapse&quot;<br>                        data-bs-target=&quot;#navbarNavDropdown&quot;<br>                        aria-controls=&quot;navbarNavDropdown&quot;<br>                        aria-expanded=&quot;false&quot;<br>                        aria-label=&quot;Toggle navigation&quot;&gt;<br>                    &lt;span class=&quot;navbar-toggler-icon&quot;&gt;&lt;/span&gt;<br>                &lt;/button&gt;<br>                &lt;div class=&quot;collapse navbar-collapse&quot; id=&quot;navbarNavDropdown&quot;&gt;<br>                    &lt;ul class=&quot;navbar-nav ms-auto&quot;&gt;<br>                        &lt;li class=&quot;nav-item text-black&quot;&gt;<br>                            &lt;a class=&quot;nav-link text-black font-weight-bold&quot; href=&quot;#&quot;&gt;About&lt;/a&gt;<br>                        &lt;/li&gt;<br>                        &lt;li class=&quot;nav-item text-black&quot;&gt;<br>                            &lt;a class=&quot;nav-link text-black font-weight-bold&quot; href=&quot;#&quot;&gt;Contact&lt;/a&gt;<br>                        &lt;/li&gt;<br>                    &lt;/ul&gt;<br>                &lt;/div&gt;<br>            &lt;/div&gt;<br>        &lt;/nav&gt;<br>        {% block content %}<br>            &lt;!-- Content Goes here --&gt;<br>        {% endblock content %}<br>        &lt;!-- Footer --&gt;<br>        &lt;footer class=&quot;py-3 bg-grey&quot;&gt;<br>            &lt;p class=&quot;m-0 text-dark text-center &quot;&gt;Copyright &amp;copy; developer&lt;/p&gt;<br>        &lt;/footer&gt;<br>        &lt;script src=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js&quot;<br>                integrity=&quot;sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz&quot;<br>                crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;<br>        &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js&quot;<br>                integrity=&quot;sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==&quot;<br>                crossorigin=&quot;anonymous&quot;<br>                referrerpolicy=&quot;no-referrer&quot;&gt;&lt;/script&gt;<br>        &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jquery-tools/1.2.7/jquery.tools.min.js&quot;<br>                integrity=&quot;sha512-sV15SgKJmAotz/5w617K9C4qN4Wj3YMk9Xf65+jzgQmPqfjwSPbwwQKdWE1hj/WjDGESqbqh4YCfL/tHgTc+EQ==&quot;<br>                crossorigin=&quot;anonymous&quot;<br>                referrerpolicy=&quot;no-referrer&quot;&gt;&lt;/script&gt;<br>    &lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>blog/templates/sidebar.html</strong></p><pre>{% block sidebar %}<br>    <br>    &lt;!-- Sidebar Widgets Column --&gt;<br>    &lt;div class=&quot;col-md-4 float-right&quot;&gt;<br>        &lt;div class=&quot;card my-4 sticky-md-top&quot;&gt;<br>            &lt;h5 class=&quot;card-header &quot;&gt;About Me&lt;/h5&gt;<br>            &lt;div class=&quot;card-body&quot;&gt;<br>                &lt;p class=&quot;card-text&quot;&gt;<br>                    This blog was built with django. <br>                &lt;a href=&quot;#&quot; class=&quot;btn btn-primary&quot;&gt;View more projects&lt;/a&gt;<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>    &lt;/div&gt;<br>{% endblock sidebar %}</pre><p><strong>blog/templates/index.html</strong></p><pre>{% extends &quot;base.html&quot; %}<br>{% block content %}<br>    &lt;style&gt;<br>    body {<br>        font-family: &quot;Roboto&quot;, sans-serif;<br>        font-size: 18px;<br>        background-color: #fdfdfd;<br>    }<br><br>    .head_text {<br>        color: white;<br>    }<br><br>    .card {<br>        box-shadow: 0 16px 48px #E3E7EB;<br>    }<br>    &lt;/style&gt;<br>    &lt;header class=&quot;masthead&quot;&gt;<br>        &lt;div class=&quot;overlay&quot;&gt;&lt;/div&gt;<br>        &lt;div class=&quot;container&quot;&gt;<br>            &lt;div class=&quot;row&quot;&gt;<br>                &lt;div class=&quot; col-md-8 col-md-10 mx-auto&quot;&gt;<br>                    &lt;div class=&quot;site-heading&quot;&gt;<br>                        &lt;h3 class=&quot; site-heading my-4 mt-3 text-white&quot;&gt;Welcome to my Blog&lt;/h3&gt;<br>                        &lt;p class=&quot;text-light&quot;&gt;Follow my journey... &amp;nbsp&lt;/p&gt;<br>                    &lt;/div&gt;<br>                &lt;/div&gt;<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>    &lt;/header&gt;<br>    &lt;div id=&quot;alert-message&quot;&gt;&lt;/div&gt;<br>    &lt;div class=&quot;container&quot;&gt;<br>        &lt;div class=&quot;row&quot;&gt;<br>            &lt;!-- Blog Entries Column --&gt;<br>            &lt;div class=&quot;col-md-8 mt-3 left&quot;&gt;<br>                {% for post in post_list %}<br>                    &lt;div class=&quot;card mb-4&quot;&gt;<br>                        &lt;div class=&quot;card-body&quot;&gt;<br>                            &lt;h2 class=&quot;card-title&quot;&gt;<br>                                &lt;a href=&quot;{% url &#39;post_detail&#39; post.slug %}&quot;<br>                                   class=&quot;link-dark  link-offset-1 link-underline link-underline-opacity-0 link-underline-opacity-75-hover&quot;&gt;{{ post.title }}&lt;/a&gt;<br>                            &lt;/h2&gt;<br>                            &lt;p class=&quot;card-text text-muted h6&quot;&gt;{{ post.author }} | {{ post.created_on }}&lt;/p&gt;<br>                            &lt;p class=&quot;card-text&quot;&gt;{{ post.content|striptags|slice:&quot;:200&quot; }}&lt;/p&gt;<br>                            &lt;a href=&quot;{% url &#39;post_detail&#39; post.slug %}&quot; class=&quot;btn btn-primary&quot;&gt;Read More &amp;rarr;&lt;/a&gt;<br>                        &lt;/div&gt;<br>                    &lt;/div&gt;<br>                {% endfor %}<br>            &lt;/div&gt;<br>            {% block sidebar %}<br>                {% include &#39;sidebar.html&#39; %}<br>            {% endblock sidebar %}<br>        &lt;/div&gt;<br>    &lt;/div&gt;<br>    {% if is_paginated %}<br>        &lt;nav aria-label=&quot;Page navigation conatiner&quot;&gt;<br>        &lt;/nav&gt;<br>        &lt;ul class=&quot;pagination justify-content-center&quot;&gt;<br>            {% if page_obj.has_previous %}<br>                &lt;li&gt;<br>                    &lt;a href=&quot;?page={{ page_obj.previous_page_number }}&quot; class=&quot;page-link&quot;&gt;&amp;laquo; PREV&lt;/a&gt;<br>                &lt;/li&gt;<br>            {% endif %}<br>            {% if page_obj.has_next %}<br>                &lt;li&gt;<br>                    &lt;a href=&quot;?page={{ page_obj.next_page_number }}&quot; class=&quot;page-link&quot;&gt;NEXT &amp;raquo;&lt;/a&gt;<br>                &lt;/li&gt;<br>            {% endif %}<br>        &lt;/ul&gt;<br>    {% endif %}<br>    <br>    {% if messages %}<br>        &lt;ul id=&quot;password-reset-messages&quot; class=&quot;messages&quot; style=&quot;display: none;&quot;&gt;<br>            {% for message in messages %}<br>                &lt;li {% if message.tags %}class=&quot;message {{ message.tags }}&quot;{% endif %}&gt;{{ message }}&lt;/li&gt;<br>            {% endfor %}<br>        &lt;/ul&gt;<br>    {% endif %}<br>{% endblock %}</pre><p><strong>blog/templates/post_detail.html</strong></p><pre>{% extends &#39;base.html&#39; %}<br>{% block content %}<br>    {% load crispy_forms_tags %}<br>    &lt;div class=&quot;container  &quot;&gt;<br>        &lt;div class=&quot;row justify-content-center&quot;&gt;<br>            &lt;div class=&quot;col-xl-8 card mb-4  mt-3 top&quot;&gt;<br>                &lt;div class=&quot;card-body&quot;&gt;<br>                    &lt;h1&gt;<br>                        {% block title %}<br>                            {{ post.title }}<br>                        {% endblock title %}<br>                    &lt;/h1&gt;<br>                    &lt;p class=&quot; text-muted&quot;&gt;{{ post.author }} | {{ post.created_on }}&lt;/p&gt;<br>                    {% if post.cover_image.url is not None %}<br>                        &lt;img src=&quot;{{ MEDIA_URL }}{{ post.cover_image.url }}&quot;<br>                             class=&quot;img-fluid&quot;<br>                             id=&quot;cover-photo&quot; /&gt;<br>                    {% endif %}<br>                &lt;/div&gt;<br>                &lt;div class=&quot;card-text px-3 ck-content&quot;&gt;{{ post.content | safe }}&lt;/div&gt;<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>        &lt;div class=&quot;row justify-content-center&quot;&gt;<br>            &lt;div class=&quot;col-xl-8 card mb-4  mt-3 &quot;&gt;<br>                &lt;div class=&quot;card-body&quot;&gt;<br>                    &lt;!-- comments --&gt;<br>                    &lt;h2&gt;{{ comments.count }} comments&lt;/h2&gt;<br>                    {% for comment in comments %}<br>                        &lt;hr class=&quot;hr my-1&quot;&gt;<br>                        &lt;div class=&quot;comments px-3 py-2&quot;&gt;<br>                            &lt;p class=&quot;font-weight-bold&quot;&gt;<br>                                {{ comment.name }}<br>                                &lt;span class=&quot; text-muted font-weight-normal&quot;&gt;{{ comment.created_on }}&lt;/span&gt;<br>                            &lt;/p&gt;<br>                            {{ comment.body | linebreaks }}<br>                        &lt;/div&gt;<br>                    {% endfor %}<br>                &lt;/div&gt;<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>        &lt;div class=&quot;row justify-content-center&quot;&gt;<br>            &lt;div class=&quot;col-xl-8 card mb-4  mt-3 &quot;&gt;<br>                &lt;div class=&quot;card-body&quot;&gt;<br>                    {% if new_comment %}<br>                        &lt;div class=&quot;alert alert-success&quot; role=&quot;alert&quot;&gt;Your comment is awaiting moderation&lt;/div&gt;<br>                    {% else %}<br>                        &lt;h3&gt;Leave a comment&lt;/h3&gt;<br>                        &lt;form method=&quot;post&quot; style=&quot;margin-top: 1.3em;&quot;&gt;<br>                            {{ comment_form | crispy }}<br>                            {% csrf_token %}<br>                            &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary  btn-lg&quot;&gt;Submit&lt;/button&gt;<br>                        &lt;/form&gt;<br>                    {% endif %}<br>                &lt;/div&gt;<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>    &lt;/div&gt;<br>&lt;/div&gt;<br>{% endblock content %}</pre><h3>Step 6: Run Application</h3><p>Running a Django application is quite straightforward. In the terminal, make sure the current directory is the project’s root folder and run the following command python manage.py runserver &lt;optional-port-number&gt; . The default port number is 8000.</p><pre>python manage.py runserver<br><br>#or<br><br>python manage.py runserver 8001 </pre><p>Once the command is run, paste this link into your browser’s address bar <a href="http://127.0.0.1:8000/">http://127.0.0.1:8000/</a> .</p><p>Note: replace ‘8000’ with your selected port if you specified a port previously.</p><p>You should see a page like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dPiqpTnoRFy18wskg7HTlQ.png" /><figcaption>Blog without blog posts</figcaption></figure><p>The next step will be to create a blog post through the admin panel</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a5507c65381" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Goals for the HNGi8 Internship -Android Track (Flutter)]]></title>
            <link>https://medium.com/@tijesu24/my-goals-for-the-hngi8-internship-android-track-flutter-29d2b87f1d5b?source=rss-3431a4612ead------2</link>
            <guid isPermaLink="false">https://medium.com/p/29d2b87f1d5b</guid>
            <dc:creator><![CDATA[Tijesunimi Adebiyi]]></dc:creator>
            <pubDate>Sun, 15 Aug 2021 21:04:24 GMT</pubDate>
            <atom:updated>2021-08-15T21:06:26.858Z</atom:updated>
            <content:encoded><![CDATA[<p>My name is Tijesu and I have always wanted to learn to code. Over the years I have tried and tried although unsuccessfully to create a career in app development but I haven’t been able to because it’s been quite difficult focusing on programming while being a student. Right now, I’m willing to give it another shot and put in all the effort so I can become a proficient and professional programmer. This is why I have joined the <a href="https://zuri.team/">Start.ng/Zuri</a> internship programme once again.</p><p>As a programmer, who started in flutter last year, I have constantly tried to become a better programmer. I joined this programme so I can kickstart my progress and develop a lot of skills needed to survive in the industry. At the end of these 8 weeks of intensive training, these are things I want to have developed.</p><h3>1. I want to develop responsive and beautiful apps</h3><p>Up till now, the apps I developed have mostly been static and ugly. I see a lot of beautiful apps I wish I could create but I haven’t been able to get the needed knowledge and experience to pull it off. That’s part of what I hope to have achieved before the end of this program.</p><h3>2. I want to be able to develop an adequate work ethic</h3><p>I expect working as a professional developer to be incredibly intense and demanding, even more when you have a deadline to fill. This will be challenging given that a lot of the time as a programmer is spent trying to solve a bug or learn a new programming concept. I believe this internship will expose me to those kinds of environments and enable me to build my persistence muscles.</p><h3>3. I would like to network with people</h3><p>This programme will offer me the opportunity to network and interact with people, a lot of whom I expect to meet with in future as potential clients, workmates or mentors. The training has a high density of people who are passionate about the craft and want to improve. I will feed off their energies as a motivation to grow.</p><p>All in all, I want to come out of this internship a better programmer and a better human with relationships that will be incredibly valuable to me.</p><p>Below are links to some tutorials for Figma, Github and Flutter:</p><p>- <a href="https://coursetro.com/posts/design/153/Figma-Tutorial---An-Introduction-to-a-Very-Impressive-UI-Design-&amp;-Prototyping-Tool">This tutorial</a>, teaches how to create an artboard in Figma.</p><p>- <a href="https://www.atlassian.com/git">This tutorial</a> shows how to use git, create a respository, push and pull from it, and commit files to it.</p><p>- <a href="https://www.solutelabs.com/blog/flutter-tutorial-for-beginners-step-by-step-guide">This tutorial</a> teaches how to setup flutter and basics of building a flutter program.</p><p><a href="https://cars.ng/">Cars.ng</a> is a site where you can buy and sell vehicles in Nigeria. It can be your first bet when planning your car purchase.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29d2b87f1d5b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>