python - NoReverseMatch in Django (url ploblem) -


i'm beginner of django want set url database field_name instead of use primary key django tutorial. code.

*mysite* **dwru/urls.py** urlpatterns = [     url(r'^$', include('product.urls', namespace="product")), ]  *myapp* **product/urls.py** urlpatterns = [    url(r'^$', views.index, name='index'),    url(r'^(?p<name_catalog>[-_\w]+)/$', views.product_list_from_index, name='catalog'), ]  **product/views.py** def product_list_from_index(request, name_catalog):    catalog = get_object_or_404(catalog, name_catalog=name_catalog)    context = {    'catalog': catalog }    return render(request,'product/product_list.html', context)   **product/models.py** class catalog(models.model):   name_catalog = models.charfield(max_length=45)   product = models.manytomanyfield(product)  **template/product/index.html** {% catalog in catalog_list %}     <h1><a href="{% url 'product:catalog' catalog.name_catalog %}">{{ catalog.name_catalog }}</h1> {% endfor %} 

then add catalog field "testca01" shown error

noreversematch @ / reverse 'catalog' arguments '(u'testca01',)' , keyword arguments '{}' not found. 1 pattern(s) tried: [u'$(?p<name_catalog>[-_\\w]+)/$'] 

it kind of problem line in template

{% url 'product:catalog' catalog.name_catalog %} 

any idea?

the $ in first url pattern might issue. dollar sign indicates it's the end of pattern, never bother include/check product urls. index url working?


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -