<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Omar Emad</title>
    <description>The latest articles on DEV Community by Omar Emad (@thepinger).</description>
    <link>https://dev.to/thepinger</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F809292%2F4e5c09b9-c506-4ffd-9b0e-c53d30d506f8.JPG</url>
      <title>DEV Community: Omar Emad</title>
      <link>https://dev.to/thepinger</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thepinger"/>
    <language>en</language>
    <item>
      <title>Deploying a Django Project on Heroku 🚀</title>
      <dc:creator>Omar Emad</dc:creator>
      <pubDate>Sat, 05 Feb 2022 22:17:17 +0000</pubDate>
      <link>https://dev.to/thepinger/deploying-a-django-project-on-heroku-1neb</link>
      <guid>https://dev.to/thepinger/deploying-a-django-project-on-heroku-1neb</guid>
      <description>&lt;p&gt;So congrats 🎉 you built your Django project and want to deploy it on Heroku 🚀. In this tutorial we are gonna go through the necessary steps to deploying a django project on Heroku, So let's start.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Libraries
&lt;/h2&gt;

&lt;p&gt;First let's start by installing a couple of necessary libraries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Install django_heroku&lt;/strong&gt;&lt;br&gt;
Install &lt;a href="https://pypi.org/project/django-heroku/"&gt;django_heroku&lt;/a&gt; library using the command below. It's a Django library for Heroku applications that ensures a seamless deployment and development experience.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip3 install django-heroku
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Note that django_heroku uses Heroku's default PostgresDB so you don't have to change anything in your &lt;code&gt;settings.py&lt;/code&gt; DATABASES variable if you want to use Postgres as your database, otherwise you have to configure your own DB and provide your credentials in the DATABASES variable.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Install gunicorn&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Install &lt;a href="https://pypi.org/project/gunicorn/"&gt;Gunicorn&lt;/a&gt; a Python WSGI HTTP Server for UNIX.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip3 install gunicorn
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Required Files
&lt;/h2&gt;

&lt;p&gt;Then let's prepare the necessary files before deployment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. requirements.txt&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You need to save all the packages you've installed and used in your project in your &lt;code&gt;requirements.txt&lt;/code&gt; file using the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip3 freeze &amp;gt; requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Procfile&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create your &lt;code&gt;Procfile&lt;/code&gt; it doesn't have any extension just type the file name like mentioned above and add these couple of lines to it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;release: export DEVELOPMENT=True
release: python manage.py makemigrations --no-input
release: python manage.py migrate --no-input

web: gunicorn [YOUR_PROJECT_NAME].wsgi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This file is responsible for running any necessary commands that you wish to execute before starting the server. Feel free to edit the file but don't remove the last line which is responsible for starting your server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. runtime.txt&lt;/strong&gt;&lt;br&gt;
Add this file and include the Python version that your project is currently using.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python-3.8.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Edit settings.py&lt;/strong&gt;&lt;br&gt;
Finally we need to add a couple of lines to your &lt;code&gt;settings.py&lt;/code&gt; file&lt;/p&gt;

&lt;p&gt;First Import the django_heroku library&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;django_heroku&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then add this line to the end of your &lt;code&gt;settings.py&lt;/code&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;django_heroku&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;locals&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Publish to GitHub
&lt;/h2&gt;

&lt;p&gt;Create a repo on GitHub and push your project. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Like you haven't done that already 👀😅&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Create Heroku App
&lt;/h2&gt;

&lt;p&gt;Create an account on Heroku if you don't have one and create a new app. Enter your app name as well as your preferred region.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--91v9N7i4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v0jk8ek8u7vdc29bwd9r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--91v9N7i4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v0jk8ek8u7vdc29bwd9r.png" alt="Image description" width="880" height="259"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Connect Heroku Project to Github Repo
&lt;/h2&gt;

&lt;p&gt;Navigate to the &lt;strong&gt;deploy&lt;/strong&gt; tab inside your app dashboard and select GitHub as your &lt;strong&gt;deployment method&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UvXPM5RV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gpzls5iuwdkjbhy2rs30.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UvXPM5RV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gpzls5iuwdkjbhy2rs30.png" alt="Image description" width="880" height="446"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Search for your repo name and click on &lt;strong&gt;Connect&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8PaOxAnt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g285wpb0n1fc7pomkder.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8PaOxAnt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g285wpb0n1fc7pomkder.png" alt="Image description" width="880" height="213"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Enable Automatic Deployments
&lt;/h2&gt;

&lt;p&gt;Under &lt;strong&gt;Automatic deploys&lt;/strong&gt; select the branch you wish to deploy 🚀 whenever new commits are pushed on that branch it gets deployed automatically or if you don't wish to do that you can just select the branch you want to deploy under &lt;strong&gt;Manual deploy&lt;/strong&gt; and then select Deploy Branch. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NpKPtWc9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e739yqnswb1tipfdxanx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NpKPtWc9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e739yqnswb1tipfdxanx.png" alt="Image description" width="880" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Check out your App
&lt;/h2&gt;

&lt;p&gt;After the deployment is successful open your app and check it out. Now you're ready to go 🚀🔥.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fpwceqpS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tpq08mr2mh1jgluzztt9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fpwceqpS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tpq08mr2mh1jgluzztt9.png" alt="Image description" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;That's it regarding deploying a Django project on Heroku. Here's the project &lt;a href="https://github.com/ThePinger/django_rest_heroku_tutorial"&gt;source code&lt;/a&gt; if you wish to check it out. Also feel free to ask any questions 😉.&lt;/p&gt;

</description>
      <category>django</category>
      <category>python</category>
      <category>heroku</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
