Django反向URL在生产中中断。

时间:2023-01-13 19:58:27

I'm running into Reverse for 'home' with arguments '()' and keyword arguments '{}' not found. This occurs for a view that takes no arguments, and is named, with and without quotation marks in the template. It only happens on my production server, not my dev environment. Both run Django 1.4.

我在“home”中遇到了相反的情况,参数“()”和关键字参数“{}”都没有找到。这种情况发生在一个视图中,该视图不接受参数,并在模板中使用引号和不使用引号进行命名。它只发生在我的生产服务器上,而不是我的开发环境。1.4运行Django。

I have the following entry for an argument-less view in my top level urls.py.

在我的*urls.py中,我有一个无参数视图的条目。

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

In course_catalog/urls.py:

在course_catalog / urls . py:

urlpatterns = patterns('course_catalog.views',
    url(r'^$', 'index', name="home"),
    ...

I also have the following in a couple of templates

我在几个模板中也有以下内容

<a href="{% url home %}">

I've also tried this in the manage.py shell:

我也在管理部门尝试过。py壳:

>>> from django.core.urlresolvers import reverse
>>> reverse('home')
'/course_catalog/'

So it seems to only happen when the template is served or something. The view itself works, by the way, if I navigate to the URL.

因此,它似乎只发生在模板被服务的时候。顺便说一下,如果我导航到URL,视图本身就可以工作。

I don't really know where to look at this point.

我真不知道该从哪里看这一点。

Any idea what could be causing this to happen? Thanks!

你知道是什么导致了这一切吗?谢谢!

1 个解决方案

#1


1  

Reverse for ''home'' with arguments '()'

“home”与参数()的反向

It seems like you are doing {% url 'home' %} in a template that doesn't have {% load url from future %}. That would explain why django double-single-quote ''home''. Like if you were doing reverse("'home'").

似乎您正在模板中执行{% url 'home' %},而模板中没有来自future %}的{% load url。这就解释了为什么django使用双引号“home”。就像你在做相反的事情(“家”)。

#1


1  

Reverse for ''home'' with arguments '()'

“home”与参数()的反向

It seems like you are doing {% url 'home' %} in a template that doesn't have {% load url from future %}. That would explain why django double-single-quote ''home''. Like if you were doing reverse("'home'").

似乎您正在模板中执行{% url 'home' %},而模板中没有来自future %}的{% load url。这就解释了为什么django使用双引号“home”。就像你在做相反的事情(“家”)。