Django Routes - How to Render a View | Python Web Development

Published: 23 June 2021
on channel: codevev
489
12

#Python #Shorts

We have created a new cool_response view. But Django doesn't know yet when to render it. For that, we need to learn Django routes.

Let's create a new urls.py file in our app, import path from django.urls and create a urlpatterns variable, which will contain a list of urls our app has.

Now we use path and as the first argument we can give it an empty string or some word if you want to have a suffix in the main url. And as the second argument we pass in the actual view we want to have rendered when this route is requested.

Lastly, we need to let our project know that we added new routes to our app. Let's go to the project's directory and find urls.py there.
Now we need to add a new route to our app here. Let's add path("cool_app/", include("cool_app.urls")). And we need to import "include" from django.urls.

-------------------------------------------------------------------------------------
Links:
Blog: https://evgenyurubkov.com
Twitter:   / evgenyurubkov  
Instagram:   / evgenyurubkov  
Youtube:    / @codevev  


Watch video Django Routes - How to Render a View | Python Web Development online without registration, duration hours minute second in high quality. This video was added by user codevev 23 June 2021, don't forget to share it with your friends and acquaintances, it has been viewed on our site 489 once and liked it 12 people.