Locked lesson.
About this lesson
Before we push our website to web hosting, we need to make a couple of slight modifications to some configuration files. In this lesson, we'll discuss important modifications, specifically: Procfile, Pip Install django_heroku, python-decouple, dj_database_url, and gunicorn.
Exercise files
Download this lesson’s related exercise files.
Create Procfile, Pip Install django_heroku, python-decouple, dj_database_url, gunicorn.docx57.7 KB Create Procfile, Pip Install django_heroku, python-decouple, dj_database_url, gunicorn - Solution.docx
58.5 KB
Quick reference
Create Procfile, Pip Install django_heroku, python-decouple, dj_database_url, gunicorn
We need to make a few changes to our app so that it works on Heroku.
When to use
Do this anytime you have an app that you want to host on Heroku.
Instructions
First, we need to create a procfile.
To create a Procfile from the terminal: touch Procfile. Inside the procfile, add this line:
web: gunicorn djangowebsite.wsgi
Pip install several new libraries:
pip install gunicorn
pip install django_heroku
pip install python-decouple
pip install dj_database_url
Hints & tips
- Add a Procfile
- Install several libraries
- 00:04 Okay, so we've got our app created on Heroku.
- 00:06 But we haven't actually pushed our website up there.
- 00:09 And before we do that, we need to make a couple of slight modifications to some
- 00:13 configuration files in order to make it play nice with Heroku.
- 00:16 Heroku has some certain requirements, and we just have to meet those requirements.
- 00:21 So that's what we're going to do in this video.
- 00:23 So let's head over to our terminal, and
- 00:26 the first thing we want to do is install three or four different things.
- 00:30 And I'm just going to do that now.
- 00:31 So we go pip install, and
- 00:33 the first thing we want is gunicorn like unicorn with a G in front of it gunicorn.
- 00:39 And this is a web server that we're going to use in Heroku,
- 00:42 Django comes with a very basic web server that we've been using.
- 00:46 Remember, it's running in our other terminal, get bashed terminal screen here.
- 00:50 But for Heroku, for professional web hosting, we need a better web server, and
- 00:54 that's what gunicorn is.
- 00:55 So pip install gunicorn, it's gone ahead and installed it.
- 00:58 Make sure again, you're in, you see this master you're in your Django website
- 01:01 directory and you see your virtual environment here.
- 01:04 So the next thing we want to install is pip install django_herok.
- 01:10 And this is just a little program that does something that Heroku wants done
- 01:14 behind the scenes.
- 01:15 So that's easy, the next one is pip install, python-decouple.
- 01:23 All right, I'm going to clear the screen here.
- 01:25 And then finally pip install
- 01:30 dj_database_url.
- 01:34 And what this does is it does some Postgres database stuff behind the scenes.
- 01:39 So Django comes with a database called SQL Lite.
- 01:42 It's a very basic database that you can use in development purposes.
- 01:45 But for professional web hosting, you need again a better database, and
- 01:50 Heroku requires the Postgres database.
- 01:53 Now, in our particular app, we're not actually doing any database stuff.
- 01:57 But still, there's that administration area that has some database stuff,
- 02:01 think back to the very beginning of the course when we looked at that.
- 02:04 So it's just a good idea to add this.
- 02:06 So okay, we've got all of the things installed that we need.
- 02:10 Now we need to add them to our app, and sort of make some configuration changes.
- 02:14 So the first thing we need to do is create a Proc file.
- 02:16 And a proc file just tells Heroku what kind of app your app is,
- 02:21 right, it's a web app.
- 02:23 So, to do that from our terminal here, we type touch,
- 02:25 that command will create a file.
- 02:27 And then we just type Procfile and make sure that P is capitalized in proc file.
- 02:32 So that worked, hopefully, we can head back over to our code here.
- 02:37 And we can see down here at the bottom, this new proc file has been created.
- 02:40 So if we click on this, now we just need to type
- 02:45 web:gunicorn, and then name our app and
- 02:51 our app's name is djangowebsite.wsgi.
- 02:56 And we can go ahead and save this.
- 02:58 And the reason why we call it Django website is because this directory right
- 03:02 here, when we first created our app, we named it Django websites.
- 03:05 That's the name of our app.
- 03:07 And you can see it's wsgi right here, response to that,
- 03:10 it's just a configuration file.
- 03:11 So that's all for this video, in the next video, we'll go ahead and
- 03:15 configure our settings.pyfile to handle all those other things we just installed
- 03:20 from the terminal and that'll be in the next video.
Lesson notes are only available for subscribers.