On 24/01/2013 10:39 AM, amy.cerr...@cbsinteractive.com wrote:
I've been trying to understand how to use generic views. I've
followed some tutorials, and read through Django docs, but I can't get
the url function to work in my templates.
I get the error
NoReverseMatch at /testadcall/
Reverse for 'detail' with arguments '(1,)' and keyword arguments '{}' not found.
in my urls.py
queryset = {'queryset': Adcall.objects.order_by('name')}
urlpatterns = patterns('django.views.generic.list_detail',
url(r'^$','object_list', queryset, name="adcalls"),
url(r'(?P<object_id>\d+)/detail/$', 'object_detail', queryset,
name="detail"),
)
in my template for the list view:
{% load url from future %}
{% if object_list %}
<ul>
{% for adcall in object_list %}
<li><a href="{% url 'detail' adcall.id %}/">{{ adcall.name
}}</a></li>
{% endfor %}
</ul>
{% endif %}
I've tried no quotes, single quotes, and double quotes around the url
name "detail", with no apparent effect.
Am I wrong in thinking that this should work?
The problem is a mismatch between your urls.py pattern and the
parameters you give to the url templatetag - note in the error message
that it mentions both arguments and keyword arguments (with your example
having a single non-keyword argument). However, in your url pattern for
the "detail" url, you use a named capture (object_id). In this case, you
must use a keyword argument to match:
{% url 'detail' object_id=adcall.id %}
Regards,
Michael.
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.