<?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 Astemir Boziy on Medium]]></title>
        <description><![CDATA[Stories by Astemir Boziy on Medium]]></description>
        <link>https://medium.com/@nartinho?source=rss-28951e1dbd7c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*j-kDF_Ws4IKWhloLhE_gRw.jpeg</url>
            <title>Stories by Astemir Boziy on Medium</title>
            <link>https://medium.com/@nartinho?source=rss-28951e1dbd7c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 02:18:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nartinho/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[How to inject a form in all pages in Django]]></title>
            <link>https://medium.com/@nartinho/how-to-inject-a-form-in-all-pages-in-django-4f4a4ca0e5b8?source=rss-28951e1dbd7c------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f4a4ca0e5b8</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Astemir Boziy]]></dc:creator>
            <pubDate>Mon, 17 Aug 2020 12:03:38 GMT</pubDate>
            <atom:updated>2020-08-17T12:03:38.909Z</atom:updated>
            <content:encoded><![CDATA[<p>Situation: you have a Django form and you want it to display on all pages of your site. For example, you want an <em>add post </em>button to be accessible in the navbar.</p><p>A possible way is to pass a form to the context of each view like in the snippet below, which is not very convenient, there can be a huge number of views in your project and to pass a form in each context of the views is a bad idea, also you need to render the form in the templates. The code will become harder to maintain.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a06fe47d1bbe77c191a3f5d86dec95dc/href">https://medium.com/media/a06fe47d1bbe77c191a3f5d86dec95dc/href</a></iframe><p>Someone may think: “Well, let me render the form in base.html that all my pages inherit!”:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/187b3a84f8841eacc4e3947f88182cda/href">https://medium.com/media/187b3a84f8841eacc4e3947f88182cda/href</a></iframe><p>but this method will not work, because we will need to write an endpoint to this view in <strong><em>urls.py</em></strong> to gain access to the view, and in this case, the form will be displayed only in <em>base.html</em>, and <em>base.html</em> is not an independent page to which user should have access.</p><h3>Context processors</h3><p>Django has a way to manage the context of all pages through the so-called <a href="https://docs.djangoproject.com/en/3.1/ref/templates/api/#writing-your-own-context-processors">context processors</a>, and it’s super easy to use. It’s a simple python function that takes one parameter and returns a dictionary.</p><p>And all we need in this case is to create a python file in our project with the following content:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a819667f5e67716c6b459cf691442a94/href">https://medium.com/media/a819667f5e67716c6b459cf691442a94/href</a></iframe><p>Then in settings.py:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15aa65cf62e5e8e5965001601710deca/href">https://medium.com/media/15aa65cf62e5e8e5965001601710deca/href</a></iframe><p>Now, in the context of each view, you will have a form and you just need to render it in <em>base.html</em> and write a view to process the form:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f43356cacea8cfa307817adc44b7c29/href">https://medium.com/media/0f43356cacea8cfa307817adc44b7c29/href</a></iframe><p>That’s it! Hope this information will be useful for you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f4a4ca0e5b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>