سلام
مطالب فوقالعاده عمیق و خوب هستن فقط کاش یه بخش جدا برای تست قرار میگرفت

سلام
تمام پیچیدگی کار در آدرس دهی مربوط به بخش ریجکسهاست که در این بخش به صورت جدولی آمده است. لینک:
https://simpleisbetterthancomplex.com/references/2016/10/10/url-patterns.html
Primary Key AutoField
-
-
- Regex
(?P<pk>\d+)
- Regex
-
- Example
url(r’^questions/(?P<pk>\d+)/$’, views.question, name=’question’) - Valid URL
/questions/934/ - Captures
{‘pk’: ‘934’}
Slug Field
- Regex
(?P<slug>[-\w]+) - Example
(r’^posts/(?P<slug>[-\w]+)/$’, views.post, name=’post’) - Valid URL
/posts/hello-world/ - Captures
{‘slug’: ‘hello-world’}
Slug Field with Primary Key
- Regex
(?P<slug>[-\w]+)-(?P<pk>\d+) - Example
(r’^blog/(?P<slug>[-\w]+)-(?P<pk>\d+)/$’, views.blog_post, name=’blog_post’) - Valid URL
/blog/hello-world-159/ - Captures
{‘slug’: ‘hello-world’, ‘pk’: ‘159’}
Django User Username
- Regex
(?P<username>[\w.@+-]+) - Example
(r’^profile/(?P<username>[\w.@+-]+)/$’, views.user_profile, name=’user_profile’) - Valid URL
/profile/vitorfs/ - Captures
{‘username’: ‘vitorfs’}
Year
- Regex
(?P<year>[0-9]{4}) - Example
(r’^articles/(?P<year>[0-9]{4})/$’, views.year_archive, name=’year’) - Valid URL
/articles/2016/ - Captures
{‘year’: ‘2016’}
Year / Month
- Regex
(?P<year>[0-9]{4})/(?P<month>[0-9]{2}) - Example
(r’^articles/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/$’, views.month_archive, name=’month’) - Valid URL
/articles/2016/01/ - Captures
{‘year’: ‘2016’, ‘month’: ’01’}
ترجمۀ اختصاصی توسط تمدن
مطلب بعدی: قالبهایی با قابلیت استفادۀ مجدد یا Reusable Templates
مطلب قبلی: استفاده از APIها در URL