1

I'm developing my own blog. Everything was good. I tried prepare it for deployment which was not successful. Now I undo all changes, but named url not working now (they were worked perfectly before): error:

Reverse for ''main_page'' with arguments '()' and keyword arguments '{}' not found

url:

urlpatterns = patterns('',
  url(r'^$', main_page, name='main_page'),
  url(r'^blog/', include('blog.blogurls')),
  url(r'^comments/', include('django.contrib.comments.urls')),
)

main page view:

def main_page(request):
  object_list = Article.objects.all()
  return render_to_response('blog/main_page.html', {'Latest': object_list}

named url used in:

<p><a href="{% url 'main_page' %}">home</a></p>
4

1 回答 1

0

替换{% url 'main_page' %}{% url main_page %}

引用 django 1.5更新日志

一个值得注意的弃用功能是转向“新型” url 标签。在 Django 1.3 之前,像 {% url myview %} 这样的语法被错误地解释(Django 认为“myview”是视图的文字名称,而不是名为 myview 的模板变量)。Django 1.3 及更高版本引入了 {% load url from future %} 语法,以引入将 myview 视为变量的更正行为。

这样做的结果是,如果您没有在模板中使用 {% load url from future %},则需要将 {% url myview %} 等标签更改为 {% url "myview" %}。如果您使用 {% load url from future %} 您可以简单地在 Django 1.5 下删除该行

于 2013-08-29T10:39:12.260 回答