Sobes.tech
Junior — Middle

What is the role of the urls.py file in the Django project structure?

sobes.tech AI

Answer from AI

The urls.py file in a Django project is responsible for routing URL requests to the appropriate handlers (views). It defines a set of rules (patterns) that link web page addresses to functions or classes that process these requests.

An example of a simple urls.py:

from django.urls import path
from . import views

urlpatterns = [
    path('', views.home, name='home'),
    path('about/', views.about, name='about'),
]

Thus, urls.py plays a key role in organizing request handling logic and site navigation.