Django-grappelli 管理员:没有反向匹配错误

发布于 2024-12-01 09:52:18 字数 1651 浏览 0 评论 0原文

我已经在一个 django 项目上工作了一段时间,该项目使用 grappelli 进行管理,今天突然我的change_form.html 模板抛出以下错误:

Caught NoReverseMatch while rendering: Reverse for "grp_related_lookup" with arguments '()' and keyword arguments '{}' not found.

违规的代码行是第 38 行:

37    $.each(related_lookup_fields_fk, function() {
38        $("#id_" + this).grp_related_fk({lookup_url:"{% url grp_related_lookup %}"});
39    });

前面是这个代码位:

var related_lookup_fields_fk = {% get_related_lookup_fields_fk adminform.model_admin %};

显然是 {% url grp_lated_lookup %} 位导致了问题。

我不明白模板如何将 grp_lated_lookup 解析为 grappelli.views.lated.lated_lookup。我尝试将 grp_lated_lookup 替换为 grappelli.views.lated.lated_lookup ,但这也不起作用。另外,在模板中,有问题的行看起来像这样:

$("#id_" + this).grp_related_fk({lookup_url:"{% url grp_related_lookup %}"});

但在错误消息中,它看起来像这样:

$("#id_" + this).grp_related_fk({lookup_url:"{% url 'grp_related_lookup' %}"});

我不知道 grp_lated_lookup 周围的单引号是否与问题有关。这就是 django 呈现函数调用的方式吗?是否将字符串 'grp_lated_lookup' 传递给 url 模板标记?如果是这样,什么可能导致它突然崩溃?

一些附加信息:

  • lated_lookup_fields 的值是一个空列表 []。我没有在 admin.py 中定义任何 lated_lookup_fields
  • 我将几个调试语句放入 grappelli.views.lated.lated_lookup 视图函数中,但它似乎没有被调用。
  • 我最近没有碰过任何模板。

希望有人能指出我正确的方向...谢谢!

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 any related_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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

↘人皮目录ツ 2024-12-08 09:52:18

您的 URLconf 中还包含 'grappelli.urls' 吗?我认为这是导致此错误的唯一原因。您可以尝试使用 python manage.py shell

from django.core.urlresolvers import reverse
print reverse('grp_related_lookup')

如果此行返回正确的 URL,则您的模板中不应出现 NoReverseMatch

grp_lated_lookup 周围的引号不应该是一个问题。 {% url %} 标签接受带引号和不带引号的字符串作为第一个参数,因此 django 将其规范化为带引号的字符串。这种行为将来将会改变:您将能够使用不带引号的字符串将模板变量传递给 {% url %}{% url foo %}{% url "foo" %} 不会给出相同的结果,请参阅 1.3 发行说明 有关详细信息。

Do you still have 'grappelli.urls' included in your URLconf? That the only reason I see that would cause this error. You can try using python manage.py shell:

from django.core.urlresolvers import reverse
print reverse('grp_related_lookup')

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.

过度放纵 2024-12-08 09:52:18

我在 Django 1.5 和 Grappelli 2.4.4 中遇到了同样的行为。

为了解决这个问题,我必须添加

url(r'^grappelli/', include('grappelli.urls')),

urlpatterns

I encountered the same behavior with Django 1.5 and Grappelli 2.4.4.

To fix the problem I had to add

url(r'^grappelli/', include('grappelli.urls')),

to urlpatterns.

两仪 2024-12-08 09:52:18

今天,当我尝试删除管理中的数据时,我遇到了这个问题。使用参数 '()' 和关键字参数 '{'app_label': ''}' 反转 'app_list' 未找到。

我已将 url(r'^grappelli/', include('grappelli.urls')) 放入 urls.py

解决方案非常奇怪:只需将 grappelli 更新到最新版本即可。 (我从2.5.6更新到2.6.3)

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.py

The solution is pretty strange: just update the grappelli to the latest version. (I updated it from 2.5.6 to 2.6.3)

月下伊人醉 2024-12-08 09:52:18

我昨天遇到了这个问题。我使用的 Django-grapelli 是包含在 FileBrowser 安装中的。我通过升级 Django-grapelli 解决了这个问题。只需输入:

pip install --upgrade django-grappelli

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:

pip install --upgrade django-grappelli
别再吹冷风 2024-12-08 09:52:18

我对 url 也有类似的问题,并注意到

{% load url from future %}

如果我想引用 url 标签,则需要在模板中使用。官方 django 文档中也提到了这一点: https://docs.djangoproject .com/en/1.3/ref/templates/builtins/#url

I had a similar issue with urls and noticed that I need

{% load url from future %}

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

烦人精 2024-12-08 09:52:18

我似乎遇到了同样的问题,但是当我运行建议的控制台测试时,我得到以下信息:

Python 2.7.9 (default, Apr  7 2015, 07:58:25)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.core.urlresolvers import reverse
>>> print reverse('grp_related_lookup')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/tsantor/.virtualenvs/project_env/lib/python2.7/site-packages/django/core/urlresolvers.py", line 579, in reverse
    return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
  File "/Users/tsantor/.virtualenvs/project_env/lib/python2.7/site-packages/django/core/urlresolvers.py", line 496, in _reverse_with_prefix
    (lookup_view_s, args, kwargs, len(patterns), patterns))
NoReverseMatch: Reverse for 'grp_related_lookup' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

我的 urls.py 看起来像这样:

urlpatterns = patterns(

    # Admin
    url(r'^grappelli/', include('grappelli.urls')),
    url(r'^admin/', include(admin.site.urls), name="admin"),

    # main views
    #url(r'^

我还运行了最新的 Grappelli (2.6.4)姜戈 (1.8.2)。顺便说一句,似乎只有当我尝试访问并添加或编辑视图时才会发生这种情况。控制面板和列表视图可以工作。

, RedirectView.as_view(url='/admin'), name='home'), # API url(r'^api/', include('api.urls', namespace='api')), )

我还运行了最新的 Grappelli (2.6.4)姜戈 (1.8.2)。顺便说一句,似乎只有当我尝试访问并添加或编辑视图时才会发生这种情况。控制面板和列表视图可以工作。

I seem to be encountering this same issue, but when I run the suggested console test I get this:

Python 2.7.9 (default, Apr  7 2015, 07:58:25)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.core.urlresolvers import reverse
>>> print reverse('grp_related_lookup')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/tsantor/.virtualenvs/project_env/lib/python2.7/site-packages/django/core/urlresolvers.py", line 579, in reverse
    return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
  File "/Users/tsantor/.virtualenvs/project_env/lib/python2.7/site-packages/django/core/urlresolvers.py", line 496, in _reverse_with_prefix
    (lookup_view_s, args, kwargs, len(patterns), patterns))
NoReverseMatch: Reverse for 'grp_related_lookup' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

And my urls.py looks like this:

urlpatterns = patterns(

    # Admin
    url(r'^grappelli/', include('grappelli.urls')),
    url(r'^admin/', include(admin.site.urls), name="admin"),

    # main views
    #url(r'^

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.

, RedirectView.as_view(url='/admin'), name='home'), # API url(r'^api/', include('api.urls', namespace='api')), )

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.

↙温凉少女 2024-12-08 09:52:18

我添加

path('grappelli/', include('grappelli.urls')),

并解决了这个问题。

I added

path('grappelli/', include('grappelli.urls')),

and fixed the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文