DEV Community

Afshar
Afshar

Posted on

2

Django and Heroku

I have used Heroku for hosting a Node.js/Express application once before. It was really easy. I created a project in Heroku, chained it to my Github project and indicated it as an automatic build. All I did was this. I just saw Heroku identifying my language and platform correctly, building and deploying it. Adding a PostgreSQL instance was not problematic too. I read the connection string from the environment, restored a backup and app get run instantly. Based on this experience, I decided to go the same path for a Django/Python project.

It did not work in the first try. Soon, I realized that I should add many stuff to project so Heroku can run my app. Additionally, as it was the first time that this project was going to be hosted in production, I did some work to get it to work. For instance, used dj_database_url for parsing PostgreSQL's connection URL. Then enabled correct CORS policy and and set ALLOWED_HOSTS.

After set the project to run correctly in a production instance, I added some stuff required by Heroku. It included Procfile and requirements.txt and their proper content. While searching online, I found Heroku's formal sample for a bare minimum Django project for Heroku. It helped me a lot. Finally, I saw my project's API run correctly and happily.

My Django/Python had an app which was based on server side rendering. I just tried that part and, oh my god! it was not working! CSS and JS files were not served correctly. I just saw a bunch of 404 errors in the browser's console. Investigating the problem, I realized that it is because of static file not configured correctly. My local had not any problem, But Heroku one showed either 404 error or Heroku build errors. I did about 10 commits so the problem solved.

I have many experiences with ASP.NET/IIS, it was not surprising me if the IIS configuration is hard. But I expected an easier process with Django/Python. By the way, project is now running in Heroku based on PostgreSQL happily!

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay