5 Tips on How to Plan a Bridal Shower

Did you know that the first bridal shower dates back to the 16th century? Well, that’s what they say! A young woman from a wealthy family fell in love with a miller’s son whom her father disapproved…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




How to Deploy a Django App on Heroku

A step by step guide.

This is the moment where some developers feels lost: the deployment time. Something that should be trivial, sometimes isn’t, but it shouldn’t be so hard at all — in fact, it is not. Hopefully, by the end of this guide, you’ll be able to host your Django project on Heroku, which is a great cloud service, especially because Heroku is a cloud PaaS (Platform as a Service) and also offers a free plan with which you can deploy your project with a full database provision.

Before you start, you have to make some configurations on your project to make it work on the server. There’s a difference between development and production and this tutorial will guide you thru it.

Note: I’m assuming you’re using a virtual environment. You also have to create a requirements.txt file and add all the python packages required to run your web application (including Django itself) to it. If you haven’t created this file, you can do this running the following command on your terminal:

First of all, you need a Procfile , which is used to declare the application process type. This file must be located in your project’s root directory. You can create one running the following command on your terminal:

Next, you need to install some packages to make the application work on the server. These are the required packages:

To install them all in once, just go to your terminal and run:

pip3 install gunicorn dj-database-url whitenoise psycopg2-binary

After the installation has completed, add them to your requirements.txt:

pip3 freeze > requirements.txt

Now you have to create a runtime.txt file in your root directory — just like the Procfile — and add the python version you’re using. To check which python version you're using, run:

The output will be something like this:

Since I’m using Python 3.8.5, to create the runtime file and add the python version, I can just run the following command:

You should also create a .gitignore file and add the sqlite database to it as long as the virtual environment folder. To do this run:

where env/ is the name of your virtual environment.

Note: The second command should use two arrows ( >>) instead of just one ( >), because you’re appending to the file. Using one single arrow ( >) would replace the content of the file with the new one.

Now you have to configure some of the project files to make the application work on the server. First, go to the settings.py file and do the following:

Yeah, that was a lot, but now your app is ready.

You also have to install the Heroku-CLI. If you are on Mac, you can install running:

If you are on Linux (Ubuntu), run:

After the installation has finished, you have to log in. On your terminal, run:

…and follow the instructions.

Now, to create a new app, run:

Next, commit your changes and push your project to deploy your app:

And that’s it, congrats! You just deployed your app. But you still have to configure the database. To add the Postgres add-on, you have to run:

Now you migrate to the database:

Finally, you have to create a superuser:

If everything went well, you’ve successfully deployed your Django app. To open your app, run:

If you got this far, congratulations! You not only deployed your project to Heroku but also learned a lot of new stuff — I hope so.

Thanks for reading!

Add a comment

Related posts:

Of Peanuts and Personas

Does our understanding of brand and user personas derive, at least partly, from the classic personality archetypes we read about as kids? Even the names you see in a typical customer segmentation…

Ingredient Sourcing and Safety

The question we are asked the most is “what is the country of origin for all of your ingredients?”, followed quickly by the comment, “I just want to make sure nothing is made in China.” Well, back in…

The Birthday Race

Towards the end of February I had to start thinking about my husband’s birthday. We are more about experiences than buying gifts but I was drawing a blank on gift ideas. I began to rack my brain…