πŸ‘¨β€πŸ’» Routing in Django ( Part 9 ) - Django For Beginners

ketanip

KetanIP

Posted on December 6, 2020

πŸ‘¨β€πŸ’» 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.

πŸ’– πŸ’ͺ πŸ™… 🚩
ketanip
KetanIP

Posted on December 6, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related