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.
00:00 Before we start building, here’s a little sneak peek again at the app that we’re building in this section, just so that you know where we’re headed.
00:11 So, I’m in my finished project. I’m going to start off the server…
00:22 and reload our page here. This is what we’re going to build. So, we have a projects index page that holds all the projects that are currently in the database. They have URLs to the images that are associated with them.
00:39 They have a title, they have some text, and then we have this option to Read More. I can click on this and it shows me a details page that exists for each of the projects where we just see the same information, but we also have this Built with: Django in here. Let’s see.
00:55 Yeah, we don’t see that here. So, it gives us a closer look at the project that we have added and that’s about it. Yeah. So, you will have the option to add as many projects as you have.
01:07 You can have images associated with them. You can have titles, you can have text. And, yeah! You can show this online and wow people with the cool stuff that you’re building.
01:18 All right? Okay, so let’s get started building some cool stuff!
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. :)
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 127.0.0.1:8000/projects/ 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 127.0.0.1:8000 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
Martin
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.
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:
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?
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?
I’m just a bit nervous!! … onto Part 4