Note_Tech

All technological notes.


Project maintained by simonangel-fong Hosted on GitHub Pages — Theme by mattgraham

Django - URLconfs functions

Back


urls functions

path()

from django.urls import include, path

urlpatterns = [
    path("index/", views.index, name="main-view"),
    path("bio/<username>/", views.bio, name="bio"),     # capture value passed to view
    path("blog/", include("blog.urls")),        # include()
]

re_path()


include()


reverse()

# url
from news import views
path("archive/", views.archive, name="news-archive")

# above url can be reverse as follow:
reverse("news-archive")     # using the named URL

from news import views
reverse(views.archive)      # passing a callable object

# use case with redirect http
from django.urls import reverse
def myview(request):
    return HttpResponseRedirect(reverse("arch-summary", args=[1945]))   # using args to pass value

# using kwargs
reverse("admin:app_list", kwargs={"app_label": "auth"}) # '/admin/auth/'


TOP