In this lesson, you’ll build out the routes for your
projects app and review what you’ve already seen on the topic. Earlier, you went to the main file inside your management app (
To that file, you added
path('projects/', include('projects.urls')). Now, when someone types
projects/ in the URL, they’ll be directed towards
urls.py inside the
So, remember what we did at the beginning? We went to the main file inside of our management app,
urls.py, and we added this
include here. We said, “Okay, if someone types in
/projects/ up in the URLs, we want to direct the person forward to
urls.py inside of the
Step one. So then, we created this file over here and inside of this file, we mimicked what we had in the other one.
django.urls import path, we did that. We created a
urlpatterns variable, and added a
path(), and what we did here is we directed it forward to the
views, inside of here. To be able to do this, we needed to import those views first.
projects we imported
views, and here’s something I want to show you. You might see it around that people use
. (dot), and
. in that case just means the current project. So you could also write
from . import views but I’m going to stay more verbose just to make it clearer.
What that allowed us to do is we got this. It’s directing forwards to a template. We still have that sitting up from the app that we built before. Let’s make a little change just to solidify this understanding of URLs, and of routes, and then paths. What I’m going to do in here, now, I will say—I’m going to add this here,
So, I still want to keep this page around, but I want it not to happen at
'projects/', which we defined up here, you see? When it ends with
'projects/' and then nothing more, it would take us there, before. Now, I changed it so it takes us there if it ends with
'test'. Let’s take a look at this.
If I reload this page, there’s nothing, because I just changed that. However, if I go to
/projects/test, we can see that page from before. So, I changed the path. That’s what I did in here. Cool.
Do you remember how this looked like in the finished app? We have this image and then descriptions down here. Let’s go ahead and set that up. So, I’m going to add another
path() that I’m going to keep empty so that it’s just
/projects/ and I will redirect to
views.—let’s call it…
03:50 So that was a quick revisit of the paths and routes. I’m going to get rid of this one now because we don’t really need to keep it around. We’re going to go ahead through the process of building out the views and the templates, very similar to how we did at the beginning in the trial lab.
Become a Member to join the conversation.