我很久没有使用过Django了。我忘了如何解决很多常见问题。 该网站是在Dj 1.3上。有一天刚开始回复错误:
Exception Value:
Reverse for 'page' with arguments '(u'yoga-class',)' and keyword arguments '{}' not found.
我没有传递任何args。传递的参数是没有域区域的域名,完整域名是yoga-class.in.ua。网站工作了2年。
查看:
class Index(ListView):
"""Front page, different from the list of posts just extra header.
On this page displayes category with checked "frontpage" checkbx."""
template_name = 'shivaapp/index.djhtml'
context_object_name = 'post_list'
def get_queryset(self):
news = PostPages.objects.filter(parent_category__frontpage=True)
news = news.order_by('move_to_top').reverse()
return news
def get_context_data(self, **kwargs):
"""Extra data for header shifters."""
context = super(Index, self).get_context_data(**kwargs)
context['slideshow'] = ShivaImage.objects.filter(
slide_show=True).order_by('ordering')
context['dictums'] = Dictum.objects.order_by('ordering')
return context
网址:
urlpatterns = patterns('',
url(r'^$', Index.as_view(paginate_by=5)),
(r'^feed/$', RSSFeed()),
(r'^search', Search.as_view()),
(r'^description/$', markdown_desc),
(r'^redirect/(?P<url>\w+)/$', redirect_view),
url(r'^cat/(?P<hash>[\w+\s]*)/$',
CategorizedPostsView.as_view(paginate_by=5)),
url(r'^page/(?P<slug>\w+)/$', PageOrSinglePost.as_view(), name='page'),
url(r'^post/(?P<slug>\w+)/$', PageOrSinglePost.as_view(), name='post'),
)
的httpd.conf:
Alias /robots.txt /var/www/path/to/robots.txt
Alias /favicon.ico /var/www/path/to/favicon.ico
AliasMatch ^/([^/]*\.css) /var/www/i159/path/to/site_media/static/css/$1
Alias /media/ /var/www/i159/path/to/media/
Alias /static/ /var/www/i159/path/to/site_media/static/
<Directory /var/www/i159/path/to/static>
Order deny,allow
Allow from all
</Directory>
<Directory /var/www/i159/path/to/media>
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias / /var/www/i159/path/to/deploy/wsgi.py
WSGIDaemonProcess local-shivablog.com python- path=/var/www/i159/data/shivablog/:/usr/bin/python2.7/lib/python2.7/site-packages
WSGIPythonHome /usr/bin/python2.7/
<Directory /var/www/i159/path/to>
<Files wsgi.py>
Order allow,deny
Allow from all
</Files>
</Directory>
我应该寻找什么?
答案 0 :(得分:2)
在您的网址正则表达式中,您使用的是\w+
,其中参数为yoga-class
。 -
不属于\w+
字符类,因此错误。
您需要更新此内容:
url(r'^page/(?P<slug>\w+)/$', PageOrSinglePost.as_view(), name='page'),
到此:
url(r'^page/(?P<slug>[\w\-]+)/$', PageOrSinglePost.as_view(), name='page'),