Monday, April 2, 2018

Re: Templates and URL Mappings

On Monday, 2 April 2018 12:00:31 UTC+1, Will Burchell wrote:

<snip>
 
from django.conf.urls import url
from . import views

app_name
= 'stock' # Referenced by template, ie <li> item in index.html

urlpatterns
= [
   
# /stock/
    url
(r'^$', views.index, name="index"),
   
# /stock/nnn/
    url
(r'^(?P<stock_id>[0-9]+)/$', views.detail, name="detail"),
   
# /stock/supplier
    url
(r'^supplier', views.supplier, name="supplier"),
   
# /stock/supplier/nnn/
    url
(r'^supplier/(?P<supplier_id>[0-9]+)/$', views.supplierdetail, name="supplierdetail"),
] 


Firstly, as a clarification, URLs don't map to templates at all; they map to views, and views may or may not render templates. But you do seem to know this.

Your problem however is simply to do with regexes; you don't terminate your supplier pattern, so it matches everything beginning with "supplier". It should be:

    url(r'^supplier$', views.supplier, name="supplier"),

or use the new path syntax in Django 2.0:

    path('supplier', ...)

-- 
DR.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5b9ca4ab-63e3-4437-aca6-925cbdccd7e9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment