1

我已经很久没有使用 Django 了。我忘记了如何解决很多常见的问题。该站点位于 Dj 1.3 上。一天刚开始返回错误:

Exception Value:    
Reverse for 'page' with arguments '(u'yoga-class',)' and keyword arguments '{}' not found.

我没有传递任何参数。传入的参数是没有域区域的域名,完整的域是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>

我应该寻找什么?

4

1 回答 1

2

In your url regex you are using \w+ where as the argument is yoga-class. The - does not belong in \w+ character class hence the error.

You need to update this:

url(r'^page/(?P<slug>\w+)/$', PageOrSinglePost.as_view(), name='page'),

to this:

url(r'^page/(?P<slug>[\w\-]+)/$', PageOrSinglePost.as_view(), name='page'),
于 2013-10-14T16:26:50.337 回答