Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Projects App Preview

Before we start building, let’s take a sneak peek at the app that you’ll build in this section so that you know where you’re headed!

In your finished project, you’re going to start up the server and reload your page. You’ll have a projects index page that holds all of the projects you have in your database, and you’ll be able to click a Read More button to get more information about each project.

Avatar image for Martie

Martie on May 12, 2020

Hi Martin,

I’m just running through this course and I’m am finding it fantastic. It’s my first time using a framework and it’s all a bit weird. I’m sure it will pay off though.

I have a couple of nagging fears that you may be able to address:

  1. Ultimately I want to be able to put a python based website “on the web”, not just run it locally. It concerns me that I need to run “python manage.py runserver” repeatedly from terminal to make it work locally. Is this also the case when it is “on the web”? or is an online virtual environment and server permanently activated and running? is the runserver command specific to a local Django webserver?

  2. Does Django make “publishing” the project simple, OR do you need to ftp all the files and structure manually AND/OR do you need to build the venv again on the web host?

  3. I’m just a bit nervous!! … onto Part 4

Avatar image for Martin Breuss

Martin Breuss RP Team on May 12, 2020

Hi @Martie and glad you’re enjoying the course so far. Web frameworks are indeed, as you said, a bit weird 😁 but you’ll get the hang of it. I gotta tell you that your worries are not unfounded, though:

Deployment can be quite hard. Essentially, yes, someone will have to set up a computer somewhere in the world that recreates your virtual environment and runs a webserver program on there that makes your app available on the internet.

That is similar to Django’s runsever, but not actually the same thing, since that’s a webserver that is only meant for development, not production. Instead, you’d hook your Django app via WSGI to e.g. gunicorn (and sometimes also nginx) and these programs would take over the job that runserver handles in your local development environment. Setting all of these pieces up in the right way is… kinda annoying and not all that easy!

However: There are some easier ways :) If you deploy your Django app on a PaaS (Platform as a Service), such as Heroku, then things go a little smoother. Heroku, for example, handles for you:

  • provisioning a Virtual Machine / Container with the right resources
  • provisioning a production database (PostgreSQL)
  • choosing and setting up your webserver (gunicorn)
  • collecting and serving your static files (via whitenoise)

These are all tasks that you have to handle yourself in deployment otherwise, and that is quite time intensive and can be complex!

Tl;dr: Your worry is real, but if you use a PaaS such as Heroku, then it’s quite doable. :)

Avatar image for Martie

Martie on May 12, 2020

Thanks Martin, I’m going to carry on tomorrow and hopefully get to the end of the course with the project finished on the local webserver.

I’ve been playing about with a cPanel approach to hosting and I have managed to get python set up and a smple python script running in a browser so I’m hopeful that I can do this … I even managed to set up a virtual environment before I knew what it actually was!!!

I’m used to html and I’ve done a bit of php with databases etc. so that doesn’t phase me too much but I still can’t get my head round what ‘file’ is actually running when I go to in this portfolio example.

I’m used to an index.html file or similar as the starting point, and I’m used to that file residing in the public-html folder, but with the virtual environment and everything I can’t fathom where all the python scripts should sit in the file structure.

The Flow Video implies that the “landing point” is ‘urls.py’ in the portfolio folder and everything flows from there.

How does which is effectively the root I guess, (e.g. www.domainname.com/) know to look for urls.py in the portfolio (project) directory.

Can you recommend any links that might be useful to explain some of this.

Many, many thanks


Avatar image for Martin Breuss

Martin Breuss RP Team on May 14, 2020

Hi @Marty! Great question, and nice work on trying out a couple of things already.

What’s Running?

For me, the most intuitive way to think about how a Django app runs on the server is to think of it as a Python script. Say, you’d execute manage.py and then it loads a bunch of settings from settings.py which next points the code forward for what database to connect to, and where to look for instructions on how to handle a HTTP request that came in.

Related to that, since you were wondering about the entry point, the information on where to look first is defined inside of settings.py. Look for a variable called ROOT_URLCONF and you will see that it points to the urls.py file of your management app. From there on, the Django Flow starts flowing in the way that I described it in this course :)

I am not familiar with PHP development, but maybe one thing to think about is that the entry point for a Django web app is not a static HTML page, such as index.html. Instead, it’s a script that is running and kept running by your web server. Hope that makes sense and clarifies it a little.

Check out this guide on How To Set Up Django with Postgres, Nginx, and Gunicorn on Ubuntu 18.04 on DigitalOcean that goes over the setup and touches on a bunch of the intricacies of running a Django app on a production web server.

Become a Member to join the conversation.