Chris Yin
Chris Yin

Reputation: 791

Django Reddit Style Voting - URL keyword argument error

Using Django Reddit Style Voting Tutorial, and getting this error. Building a Q&A style site that displays a topic, then questions related to that topic, and then answers associated with the question.

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

Here's my code

#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)),

My index view lists all of the topics and renders on index.html, and then each topic has an ID, and the questions associated with that ID are then rendered on the next page, questions.html.

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

How do I fix the error? I need movie_id b/c that's how I render the next page with associated questions, but I can't pull up the next page.

Upvotes: 0

Views: 186

Answers (1)

user1462141
user1462141

Reputation: 252

I went through the pains of that outdated documentation myself. Here is how I got it to work:

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

Also, you may want to add this to the 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",)                                                                                                                  

Upvotes: 1

Related Questions