django
Think of a college. It's a huge building with many classrooms and departments. You want to find your class, so you approach the receptionist and ask, "Where can I find the I Year ECE class?" The receptionist checks the information and directs you to the correct classroom.
In a similar way, when you request a URL such as /videosnap/account/ through your browser, Django's URL resolver acts like the receptionist. It looks at the URL you requested and directs that request to the appropriate view, which handles the request and sends a response back to the browser and college buliding mapis similar to URLConf.
URL → Uniform Resource Locator
A URL is like an address on the internet ,It tells the browser where to find or request something.
Django allows us to define and customize our own URLs with the help of URLConf.
URLConf the name itself suggest's URL Configuration it is where we define urlpatterns for django applications and map them to views.This configuration is done in "urls.py" using path() function and pass a few arguments to this function.
For example
from django.urls import path
urlpatterns=[
path("accounts/",views.profile,name="accounts"),
path("posts/",views.create_post,name="create_post"),
]
So here “accounts/” → route
views.profile → It is the view(function) associated to the route “accounts/”
name → Naming your URL lets you refer to it unambiguously from elsewhere in Django, especially from within templates. This powerful feature allows you to make global changes to the URL patterns of your project while only touching a single file.
So whenever we request www.videosnap.com/accounts/, Django receives the request, checks the requested URL against the URL patterns defined in URLconf, and if a matching pattern is found, Django calls the corresponding view."
Django URLs Functions
Django URLs function handles the user request and maps the request to respective views. Let's discuss the important django.urls function in detail:
Function Name | Syntax | Purpose |
path() | path(route, view, name) | Used to define a URL pattern and map it to a view; use it for normal URL routing in Django. |
re_path() | re_path(route, view, name) | Used to define a URL pattern using regular expressions when |
include() | include(module, namespace) ,include(pattern_list) | Used to include URL patterns from another |
register_converter() | register_converter(converter, type_name) | Used to register a custom path converter when Django's built-in converters ( |
Join Techsnap Creators
Share your knowledge and earn ??
Want to showcase your tech expertise and get rewarded for your insights? Join the Techsnap creator network!
Write insightful blogs, stay ahead of industry trends, and grow your professional brand while helping others in the community.
Ready to make an impact?

Comments