DEV Community

Cover image for 👨‍💻 Routing in Django ( Part 9 ) - Django For Beginners
KetanIP
KetanIP

Posted on • Originally published at ketaniralepatil.com

👨‍💻 Routing in Django ( Part 9 ) - Django For Beginners

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
Enter fullscreen mode Exit fullscreen mode

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"),
]
Enter fullscreen mode Exit fullscreen mode

The syntax for path is as follows,

path( route, view, name )
Enter fullscreen mode Exit fullscreen mode

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)