#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
Смотрите видео Django Routes - How to Render a View | Python Web Development онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь codevev 23 Июнь 2021, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 489 раз и оно понравилось 12 людям.