Django Url Pass Parameter To View Code Example


Example 1: django slug int url mapping

# in views define the int slugs then the url mapping is like this  from django.urls import path, re_path  from . import views  urlpatterns = [     path('articles/2003/', views.special_case_2003),     re_path(r'^articles/(?P<year>[0-9]{4})/$', views.year_archive),     re_path(r'^articles/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/$', views.month_archive),     re_path(r'^articles/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<slug>[\w-]+)/$', views.article_detail), ]

Example 2: django get parameters from url

message = request.GET.get('message')

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable