2013-08-29 29 views
1

我正在開發自己的博客。一切都很好。我嘗試過爲部署做好準備,但沒有成功。現在,我取消所有更改,但名爲url現在不工作(他們是完美的工作之前): 錯誤:命名的網址不工作在Django 1.5和Python 2.7

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

網址:

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

主要頁面視圖:

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

命名的url用於:

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

回答

0

{% url 'main_page' %}替換爲{% url main_page %}。從Django的1.5 changelog

報價:

One deprecated feature worth noting is the shift to 「new-style」 url tag. Prior to Django 1.3, syntax like {% url myview %} was interpreted incorrectly (Django considered "myview" to be a literal name of a view, not a template variable named myview). Django 1.3 and above introduced the {% load url from future %} syntax to bring in the corrected behavior where myview was seen as a variable.

The upshot of this is that if you are not using {% load url from future %} in your templates, you’ll need to change tags like {% url myview %} to {% url "myview" %}. If you were using {% load url from future %} you can simply remove that line under Django 1.5

+0

它的工作。但我不記得模板中有任何更改。 thanx – user2647448

+0

你的模板中是否有'{%load url from future%}? – alecxe

+0

不!未來有什麼網址? – user2647448