I'm a beginner of Django I want to set my url with database field_name 
instead of use primary key from Django tutorial. This is my 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**{% for catalog in catalog_list %}
    <h1><a href="{% url 'product:catalog' catalog.name_catalog %}">{{ 
catalog.name_catalog }}</h1>{% endfor %}

Then I add Catalog field with "TestCa01" then it shown an error

NoReverseMatch at /Reverse for 'catalog' with arguments '(u'TestCa01',)' and 
keyword arguments '{}' not found. 1 pattern(s) tried: 
[u'$(?P<name_catalog>[-_\\w]+)/$']

it kind of some problem with this line in template

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

any Idea?

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/65b8fb8e-02ae-4441-88cc-114eb662cdee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to