Django Reddit Style Voting - URL关键字参数错误

时间:2012-11-09 03:28:21

标签: python html django

使用Django Reddit Style Voting Tutorial,并收到此错误。构建一个Q& A样式网站,显示一个主题,然后是与该主题相关的问题,然后是与该问题相关的答案。

TypeError at /home/1/
object_list() got an unexpected keyword argument 'movie_id'

这是我的代码

#urlconf
url(r'^$', 'index'),
url(r'^(?P<movie_id>\d+)/$', object_list, dict(queryset = Question.objects.all(), 
        template_object_name = 'question', template_name = 'qanda/questions.html', 
        paginate_by = 15, allow_empty = True)),

我的索引视图列出了index.html上的所有主题和呈现,然后每个主题都有一个ID,然后在下一页(questions.html)上呈现与该ID相关的问题。

#index.html
{% if latest_movie_list %}
    {% for movie in latest_movie_list %}
        <li><a href="/home/{{ movie.id }}/">{{ movie.title }}</a></li>
{% endfor %}

如何修复错误?我需要movie_id b / c,这就是我如何使用相关问题呈现下一页,但我无法提起下一页。

1 个答案:

答案 0 :(得分:1)

我自己经历了那些过时文档的痛苦。以下是我如何使用它:

How do you join two tables using Django without using raw sql?

此外,您可能希望将其添加到voting / urls.py

 url(r'^links/(?P<object_id>\d+)/(?P<direction>up|down|clear)vote/?$',                                                                                                                
     vote_on_object,                                                                                                                     
     dict(                                                                                                                               
         model=Movie,                                                                                                                     
         template_object_name='link',                                                                                                    
         template_name='movie/link_confirm_vote.html',                                                                                    
         allow_xmlhttprequest=True,                                                                                                      
         ),                                                                                                                              
     name="link_vote",)                                                                                                                  
相关问题