Sobes.tech
Junior — Middle

Have you ever configured URL routing in Django projects?

sobes.tech AI

Answer from AI

Yes, I have configured URL routing in Django projects. Routing in Django is managed through the urls.py file, where paths and their corresponding views are defined.

Example of simple routing setup:

from django.urls import path
from . import views

urlpatterns = [
    path('', views.index, name='index'),
    path('articles/<int:year>/', views.articles_by_year, name='articles_by_year'),
]

Here:

  • The empty string '' matches the root URL and calls the index function.
  • The 'articles/<int:year>/' path takes a parameter year and passes it to articles_by_year.

This approach allows flexible URL management and linking to request handling logic.