<?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 Divinedaniel on Medium]]></title>
        <description><![CDATA[Stories by Divinedaniel on Medium]]></description>
        <link>https://medium.com/@divinedaniel202?source=rss-ba368ffbdc56------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*6VYwVjQ0eV-iYuxz</url>
            <title>Stories by Divinedaniel on Medium</title>
            <link>https://medium.com/@divinedaniel202?source=rss-ba368ffbdc56------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 12:43:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@divinedaniel202/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 setup a docker for Django, Celery, Redis, and Postgres using a notes application.]]></title>
            <link>https://medium.com/@divinedaniel202/how-to-setup-a-docker-for-django-celery-redis-and-postgres-using-a-notes-application-b9d3c49c85a6?source=rss-ba368ffbdc56------2</link>
            <guid isPermaLink="false">https://medium.com/p/b9d3c49c85a6</guid>
            <dc:creator><![CDATA[Divinedaniel]]></dc:creator>
            <pubDate>Sat, 01 Mar 2025 17:21:28 GMT</pubDate>
            <atom:updated>2025-03-01T17:21:28.813Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi guys, today we will be working with Django and docker to create a docker container the contains our entire application to be able to work on any environment and operating system. We setup our docker container with Postgres for database, Celery for asynchronous programming and Redis is for process management ofr the workers. And finally we will make it accessible for others.</p><p><strong>WHY WE NEED DOCKER?</strong></p><p>Docker is a tool used to simulate an Operating system to run your application as a live server. With a docker container, you will be able to run your application on any operating system anytime, anywhere.</p><p>The Prerequisite for this are as follows:</p><ul><li>Python basics</li><li>Django basics</li><li>Python installed on your system</li><li><a href="https://medium.com/@divinedaniel202/how-to-connect-django-to-postgresql-and-env-python-decouple-in-a-local-environment-41246d94777">setup your Postgres database</a></li></ul><p>Let us setup our Django applications. We will first setup our Django Project. the first step is to create your virtual environment. If you don’t have your virtual environment, you just need to install <em>virtualenv </em>using pip in your terminal or for windows(command).</p><pre>pip install virtualenv</pre><p>Then, enter the following command to create our virtual environment:</p><pre>virtualenv venv</pre><p>The “venv” name is just a generic name. We will name our virtual environment whatever you want.</p><p>The next step is to enter the virtual environment.</p><p>For Windows:</p><pre>venv\Scripts\activate</pre><p>For Mac or Linux:</p><pre>source venv/bin/activate</pre><p>Now, we install Django and start our Django Project:</p><pre>pip install django djangorestframework</pre><pre>django-admin startproject docker_django</pre><p>We can create an application in the project so we can test the connection:</p><pre>django-admin startapp main</pre><p>Now the fun begins: We can open our favorite editor. I will be using V<a href="https://code.visualstudio.com/">isual Studio Code</a>.</p><p>Next we go to the <strong><em>settings.py </em></strong>to change a few things. The first thing will be to add the new app “main” to our INSTALLED_APPS</p><pre>INSTALLED_APPS = [<br>      ...<br>    &#39;rest_framework&#39;,<br>      ...<br>    &#39;main&#39;,<br>      ...<br>    ]</pre><p>We need to install python decouple</p><pre>pip install python-decouple</pre><p>we will not configure our PostgreSQL to work as a “.env” for our database setup. First we will import the ‘config’ from ‘decouple’.</p><pre>from decouple import config<br>....<br>DATABASES = {<br>    &quot;default&quot;: {<br>        &quot;ENGINE&quot;: &quot;django.db.backends.postgresql&quot;,<br>        &quot;NAME&quot;: config(&quot;DB_NAME&quot;),<br>        &quot;USER&quot;: config(&quot;DB_USER&quot;),<br>        &quot;PASSWORD&quot;: config(&quot;DB_PASSWORD&quot;),<br>        &quot;HOST&quot;: config(&quot;DB_HOST&quot;),<br>        &quot;PORT&quot;: config(&quot;DB_PORT&quot;),<br>    }<br>}</pre><p>Now let us create the ‘.env file in the ‘docker_django’ app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*ZLgyYVOapWbgdPQloCH_ug.png" /><figcaption>the ‘.env’ file is by the left</figcaption></figure><p>Now let us test the connection, so I will make a simple notes list with this excercise. We will need to install Django rest framework, ‘psycopg2-binary’ for the PostgreSQL, “celery” for the worker node and “redis” to manage the worker nodes.</p><pre>pip install celery redis psycopg2-binary</pre><p>Now Let us begin the setting up our project.</p><p>We will work on the todo list “models.py”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*yEh9_7zXaz6rVLo0vgITaQ.png" /><figcaption>“models.py” for the note todo list</figcaption></figure><p>Now the “Serializers.py” for the main app</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*hxm4p775FqHJO5mNn6wizw.png" /><figcaption>“serlializers.py” for the note todo list</figcaption></figure><p>Then the “Views.py”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*Fa58ku7I13Qxg3R_cFSk7A.png" /><figcaption>“views.py” for the note todo list</figcaption></figure><p>Our “Urls.py”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*S1CeD9O1FR276zc9FQ2TUA.png" /><figcaption>“urls.py” for the note todo list</figcaption></figure><p>Our base “Urls.py”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*ZcsaVBr1_mA-DlNbNvETMQ.png" /><figcaption>“urls.py” for the base django setup</figcaption></figure><p>Let us setup our celery for asynchronous event.</p><p>Now to the main event</p><p>Our Docker Container will be created as “dockerfile”. it is this exact name so your django application can recognize the file. Don&#39;t worry, i will explain each line and what they mean.</p><p>We will create our “dockerfile” and add a few parameter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*amX3RJ4iHq0Mln7RRWrEow.png" /><figcaption>Dockerfile configuration</figcaption></figure><p>I wrote what each line of code does. That is our base setup for now, i will add a few more parameter later. For Now let us setup our Docker-compose.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*LfiX1SdaLs79C1eD3Ct86g.png" /><figcaption>docker-compose.yaml for the docker commands</figcaption></figure><p>Let us setup the application to run a celery operation so we can test it. But first, let us create an asynchronous event, which in this case will be sending an OTP to the user once the user registers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9d3c49c85a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HOW TO CONNECT DJANGO TO POSTGRESQL AND .ENV (PYTHON-DECOUPLE) IN A LOCAL ENVIRONMENT]]></title>
            <link>https://medium.com/@divinedaniel202/how-to-connect-django-to-postgresql-and-env-python-decouple-in-a-local-environment-41246d94777?source=rss-ba368ffbdc56------2</link>
            <guid isPermaLink="false">https://medium.com/p/41246d94777</guid>
            <dc:creator><![CDATA[Divinedaniel]]></dc:creator>
            <pubDate>Tue, 30 May 2023 02:29:40 GMT</pubDate>
            <atom:updated>2023-06-14T00:41:15.340Z</atom:updated>
            <content:encoded><![CDATA[<h3>HOW TO CONNECT DJANGO TO POSTGRESQL AND .ENV (PYTHON-DECOUPLE) IN A LOCAL ENVIRONMENT</h3><p>Hi guys, today i will be showing you how to connect your Django application to your PostgreSQL database.</p><p>The prerequisites for this tutorial are:</p><ul><li>Python</li><li>Django(basics)</li><li>ProgreSQL(basics)</li></ul><p>The first step is to create your virtual environment. If you don’t have your virtual environment, you just need to install <em>virtualenv </em>using pip in your terminal or for windows(command).</p><pre>pip install virtualenv </pre><p>Then, enter the following command to create our virtual environment:</p><pre>virtualenv venv</pre><p>The “venv” name is just a generic name. We will name our virtual environment whatever you want.</p><p>The next step is to enter the virtual environment.</p><p>For Windows:</p><pre>venv\Scripts\activate</pre><p>For Mac or Linux:</p><pre>source venv/bin/activate</pre><p>Now, we install Django and start our Django Project:</p><pre>pip install django djangorestframework</pre><pre>django-admin startproject postgres_django</pre><p>We can create an application in the project so we can test the connection:</p><pre>django-admin startapp main</pre><p>Now the fun begins: We can open our favorite editor. I will be using V<a href="https://code.visualstudio.com/">isual Studio Code</a>.</p><p>In the ‘Explorer’ tab, the structure of the project can be seen:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tss8TXVUN3QbNb4t8efB8Q.png" /></figure><p>Next we go to the <strong><em>settings.py </em></strong>to change a few things. The first thing will be to add the new app “main” to our INSTALLED_APPS</p><pre>INSTALLED_APPS = [<br>      ...<br>    &#39;rest_framewor&#39;,<br>      ...<br>    &#39;main&#39;,<br>      ...<br>    ]</pre><p>Now let us setup our postgresql</p><p><a href="https://www.postgresql.org/download/">Downloads</a></p><p>go to the link above and select your operating system then install it using the instructions offered by the application.</p><p>Next we should be left with a screen like this on our pg admin:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z8cC4dy9AtCknHYVhOabSg.png" /></figure><p>input your set password and then click “ok”.</p><p>Then we go to the server open it and go to the “database”. then right-click and select “create”, next we select “Database”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E6dVFn2o0Ur5GR33Dadp7Q.png" /></figure><p>Once we do that a modal will show wher we will input the name of the new database want to add the name of your database to ‘Database’ input. Then save.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CUSQhkOhBxdYJcpvLA-EyA.png" /></figure><p>See what the structure looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jUcitiT6GzHKS0BkT4F65Q.png" /></figure><p>Now we go to the Server ‘Postgres’ right-click and select ‘properties’ . Once we select that select the connection bar the modal that comes up. We will see the informations we use next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CaEPCMdR2MVnQH90H0MHIg.png" /></figure><p>Now let’s get back to the ‘settings.py’ in out django project. I will first going to show you how it is normally then we will move the information to the .env file.</p><pre>DATABASES = {<br>    &quot;default&quot;: {<br>        &quot;ENGINE&quot;: &quot;django.db.backends.postgresql&quot;,<br>        &quot;NAME&quot;: &#39;postgres-django&#39;,<br>        &quot;USER&quot;: &#39;postgres&#39;,<br>        &quot;PASSWORD&quot;: &#39;****&#39;,<br>        &quot;HOST&quot;: &#39;localhost&#39;,<br>        &quot;PORT&quot;: &#39;5432&#39;,<br>    }<br>}</pre><p>We need to install python decouple</p><pre>pip install python-decouple</pre><p>we will not configure our PostgreSQL to work as a “.env” for our database setup. First we will import the ‘config’ from ‘decouple’.</p><pre>from decouple import config<br>....<br>DATABASES = {<br>    &quot;default&quot;: {<br>        &quot;ENGINE&quot;: &quot;django.db.backends.postgresql&quot;,<br>        &quot;NAME&quot;: config(&quot;DB_NAME&quot;),<br>        &quot;USER&quot;: config(&quot;DB_USER&quot;),<br>        &quot;PASSWORD&quot;: config(&quot;DB_PASSWORD&quot;),<br>        &quot;HOST&quot;: config(&quot;DB_HOST&quot;),<br>        &quot;PORT&quot;: config(&quot;DB_PORT&quot;),<br>    }<br>}<br></pre><p>Now let us create the ‘.env file in the ‘postres-django’ app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GBoCn9R-FTGUDdCHdwnOIw.png" /></figure><p>Now let us add the variables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RuHjtVFPP_RGVbkFSKySTQ.png" /></figure><p>Now let us test the connection, so I made a simple registration app. We will need to install Django rest framework and ‘psycopg’ for the PostgreSQL.</p><pre>pip install psycopg2</pre><p>we will just test this by registering a user and return the user’s information</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eFdvr8xxQ4SAsB8UZHt0fQ.png" /><figcaption>serializers.py</figcaption></figure><p>then the view will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p5fwbifkmvdkLdZZg1t95g.png" /></figure><p>the base urls.py will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1M2E5zNb6mB2TQ7E3WrGjw.png" /></figure><p>the main urls.py will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SXPfcH7bYGschnvqmg6D8Q.png" /></figure><p>then we can run the make migrations and migrate command</p><pre>python manage.py makemigrations<br>python manage.py migrate</pre><p>then the run server</p><pre>python manage.py runserver</pre><p>we will now test the endpoint</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ea2P6oYKqQKaD9dG281ZPQ.png" /></figure><p>the response will look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K_yVSuIzn9BzAM18IO3wpg.png" /></figure><p>let’s now check what the database looks like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yVyokr5-1YdZS2CmumZI5A.png" /></figure><p>With that you see that the connection worked.</p><p>You can see the whole code <a href="https://github.com/divinedanny/postgres-django.git">here</a>. Thank you. Follow me for more content like this.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41246d94777" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>