‍ Routing in Django ( Part 9 ) – Django For Beginners

Django For Beginners (7 Part Series)

1 ‍ Getting Started With Django ( Part 1 ) – Django For Beginners
2 Models In Django
3 more parts…
3 Exploring Django Project Structure ( Part 3 ) – Django For Beginners
4 ‍ Basic operations on Models In Django ( Part 6 ) – Django For Beginners
5 ‍ Queries in Django ( Part 7 ) – Django For Beginners
6 ‍ Basics of Views and Routing in Django ( Part 8 ) – Django For Beginners
7 ‍ 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.

Django For Beginners (7 Part Series)

1 ‍ Getting Started With Django ( Part 1 ) – Django For Beginners
2 Models In Django
3 more parts…
3 Exploring Django Project Structure ( Part 3 ) – Django For Beginners
4 ‍ Basic operations on Models In Django ( Part 6 ) – Django For Beginners
5 ‍ Queries in Django ( Part 7 ) – Django For Beginners
6 ‍ Basics of Views and Routing in Django ( Part 8 ) – Django For Beginners
7 ‍ Routing in Django ( Part 9 ) – Django For Beginners

原文链接:‍ Routing in Django ( Part 9 ) – Django For Beginners

© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容