Django, Heroku, Web Development

Deploy Django Project on Heroku

Take your Technical projects to next level.

--

As we know Django is python based open-source framework which follows MVC(Model View Controller) architectural pattern used in the rapid development of the website with clean design without worrying too much about setting up an environment to start.

I am using python 3.8.3 version and VS code as my text editor. deploying a Django project on Heroku is often difficult. To deploy it with ease some steps are needed to be followed :

  1. Create a Heroku account :

creating a Heroku account is very simple. visit https://dashboard.heroku.com/ so signup as a new account by tapping on signup button located in the top-right corner

After successful signup and login proceed to next step.

2. Create a Django app :

create a fresh Django app using -

or you can use your project make sure you are inside your project folder where manage.py file is present.

3. Create a Virtual Environment and Install required dependencies :

Install basic libraries using pip like pip install Django and most important install gunicorn(WSGI application server) and white noise.

After installation of all libraries run the command :

It creates a new file in the root directory which consists of all libraries used in Django named requirements.txt which helps Heroku to install dependencies before deploying.

4. Create an App on Heroku site :

By clicking on creating new app add the name you want for your app then open settings tabs, tap on add build pack and tap on python to set python as your build pack and save changes.

5. Addition of required files :

Now create two new files runtime.txt in which specify the version of python used and other Procfile with no extension.

here gunicorn in place of vidz you need to enter your project folder name which contains settings.py file

5. Changes in settings.py file

Click on your Heroku project then tap on an open app button present in the top right corner it opens up the link where the project will be deployed. copy the link and paste it in settings.py allowed host section with local server to run it locally and change DEBUG to false as well.

Now add white noise as middleware in Django settings.py middleware section.

Add STATIC_ROOT to configure static files

6. Connect GitHub repository to Heroku :

After changes push the project to Github

In Heroku deploy section connect GitHub repository by tapping on connect to Github.

After completion tap on deploy

Voila, Project is Deployed.

Conclusion:

Hopefully, this article about Django project deployment clears your imagination about deployment and also encourages you to learn more about web development.

Thank you so much for reading this, also share this article.

Feel free to connect:

LinkedIN ~ https://www.linkedin.com/in/priyanshsinghal/

Instagram ~ https://www.instagram.com/18_priyansh/

Github ~ https://github.com/priyansh18

Follow for more…

Cheers.

--

--