I've been working on a django project for a while now that uses grappelli for the admin and all of a sudden today my change_form.html template is throwing the following error:
Caught NoReverseMatch while rendering: Reverse for "grp_related_lookup" with arguments '()' and keyword arguments '{}' not found.
The offending line of code is line 38:
37 $.each(related_lookup_fields_fk, function() {
38 $("#id_" + this).grp_related_fk({lookup_url:"{% url grp_related_lookup %}"});
39 });
which is preceded by this bit of code:
var related_lookup_fields_fk = {% get_related_lookup_fields_fk adminform.model_admin %};
Obviously it's the {% url grp_related_lookup %}
bit that's causing the problem.
I don't understand how the template is resolving grp_related_lookup
to grappelli.views.related.related_lookup
. I have tried replacing grp_related_lookup
with grappelli.views.related.related_lookup
and that didn't work either. Also, in the template the offending line looks like this:
$("#id_" + this).grp_related_fk({lookup_url:"{% url grp_related_lookup %}"});
but in the error message it looks like this:
$("#id_" + this).grp_related_fk({lookup_url:"{% url 'grp_related_lookup' %}"});
I don't know if the single quotes surrounding grp_related_lookup
might have something to do with the problem or not. Is that how django rendered the function call? Is it passing the string 'grp_related_lookup'
to the url template tag? If so, what might have caused this to break suddenly?
Some additional info:
- The value of
related_lookup_fields
is an empty list[]
. I am not defining anyrelated_lookup_fields
in my admin.py. - I threw a couple debug statements into the
grappelli.views.related.related_lookup
view function and it doesn't appear to be getting called. - I have not touched any of the templates recently.
Hopefully someone can point me in the right direction... Thanks!
I faced this problem yesterday. The Django-grapelli I used was the one that was included in the FileBrowser installation. I solved the problem by upgrading Django-grapelli. Just type:
I encountered the same behavior with Django 1.5 and Grappelli 2.4.4.
To fix the problem I had to add
to
urlpatterns
.I faced with this problem today, when I tried to delete data in admin.
Reverse for 'app_list' with arguments '()' and keyword arguments '{'app_label': ''}' not found.
I have put the
url(r'^grappelli/', include('grappelli.urls'))
in urls.pyThe solution is pretty strange: just update the grappelli to the latest version. (I updated it from 2.5.6 to 2.6.3)
I had a similar issue with urls and noticed that I need
in the template if I want to have quoted url tags. That's also mentioned in the official django documentation: https://docs.djangoproject.com/en/1.3/ref/templates/builtins/#url
Do you still have
'grappelli.urls'
included in your URLconf? That the only reason I see that would cause this error. You can try usingpython manage.py shell
:If this line returns the correct URL, you shouldn't get a
NoReverseMatch
in your template.The quotes around
grp_related_lookup
shouldn't be a concern. The{% url %}
tag accepts both quoted and unquoted strings as first argument, so django normalizes it to quoted strings. This behaviour is going to change in the future: you'll be able to pass template variables to{% url %}
using unquoted strings.{% url foo %}
and{% url "foo" %}
won't give the same result, see the 1.3 release notes for details about this.I seem to be encountering this same issue, but when I run the suggested console test I get this:
And my
urls.py
looks like this:I also have the latest Grappelli (2.6.4) running on Django (1.8.2). By the way, it seems it only occurs when I try to access and add or edit view. The control panel and list views work.