This post was originally posted here 👨💻 Routing in Django ( Part 9 ) - Django For Beginners.
This is part of the series Django For Beginners we are going to see about apps in app and we will see about urls in python.
In this post we are going to learn all about urls in django,, let's get started.
Understanding URLS in Django
Let us first understand where we write our urls, we write our urls in our project folder in urls.py
file, as shown below.
📂 myDjangoSite
- 📂 myDjangoSite
- 📄 __init__.py
- 📄 asgi.py
- 📄 settings.py
- 📄 urls.py
- 📄 wsgi.py
- 📄 manage.py
In urls.py
specifically we write path for our django website in urlpatterns
list, in a patterns as shown below,
from django.urls import path
from . import views
urlpatterns = [
path('', views.Home, name="home"),
path('about/', views.About, name="about"),
]
The syntax for path is as follows,
path( route, view, name )
Where route is a string argument and denotes the relative path we want for that view. View is a view
it may be a class-base or a function-based view...
Sorry to interrupt you, you can read this complete post here 👨💻 Routing in Django ( Part 9 ) - Django For Beginners.
Top comments (0)