[Answered ]-Can't get the url function to work with a specific syntax in django

2👍

Unless your view is named ‘view’ in the urlconf, you should use the full python dotted import path in the tag. For example:

{% url 'my_app.views.my_view' obj.id %}

If you want to test it properly, you can also use the django shell

python manage.py shell

and try the ‘reverse’ function:

from django.core.urlresolvers import reverse
reverse('my_app.views.my_view' args=[1])

>> '/my/awesome/url/1'

edit: also make sure that you didn’t namespace your urls, if you did, you should include the namespace in the url tag:

{% url 'namespace:view' obj.id %}

another edit, because I have a feeling this might be it. I apologise for abusing the answer system instead of comments, but since I’m only starting out my reputation is too low.

Can you post the full urlconfig from your root urls.py up until the ‘misbehaving’ url? I have had cases where an url captured a group (say, an ID) and then included a bunch of other urls, leading to two required arguments for the reverse function.

👤BBT

Leave a comment