python - No Content matches the given query. (Django) -


i trying complete 'hackernews clone tutorial (django unchained tuts+) can head around using django noob. stuck on creating points/vote system. instead of votes being applied specific peice of content getting 404 error

page not found (404) request method: request url:    http://localhost:8000/vote/ no content matches given query. 

here code.

voting in views.py

def vote(request):   content = get_object_or_404(content, pk=request.post.get('content'))   content.points += 1   content.save()   return httpresponseredirect('/') 

urls.py (inside of 'collection')

from django.conf.urls import patterns, include, url  urlpatterns = patterns('',      url(r'^$', 'collection.views.index'),     url(r'^content/$', 'collection.views.content'),     url(r'^vote/$', 'collection.views.vote'), ) 

index.html

{% extends 'layouts/base.html' %} {% load staticfiles %} {% load content_extras %}  {% block head %}     <script src='{% static 'js/jquery-1.11.3.min.js' %}'></script>     <script src='{% static 'js/vote.js' %}'></script> {% endblock head %}  {% block content %}      <ol>         {% content in contents %}         <li>             <p>                 <a href='/vote/' id='content-vote-{{ content.id }}'>+rep</a>                 <a href='{{ content.url }}' id='content-title-{{ content.id }}'>{{ content.title }}</a><span class="domain">({{ content.domain }})</span>             </p>             <p>                 {{ content.points }}points {{ content.moderator.username }}{{ content.created_at|age }}             </p>         </li>         {% endfor %}     </ol> {% endblock %} 

ajax

    $(document).ready(function() {      // using jquery function getcookie(name) {     var cookievalue = null;     if (document.cookie && document.cookie != '') {         var cookies = document.cookie.split(';');         (var = 0; < cookies.length; i++) {             var cookie = jquery.trim(cookies[i]);             // cookie string begin name want?             if (cookie.substring(0, name.length + 1) == (name + '=')) {                 cookievalue = decodeuricomponent(cookie.substring(name.length + 1));                 break;             }         }     }     return cookievalue; } var csrftoken = getcookie('csrftoken');  function vote(content){     $.ajax({         type: 'post',         url: '/vote/',         data: {'content': contentid},         success: function(){             $("#content-vote-" + contentid).hide():             $("#content-title-" + contentid).css({'margin-left:'15px});          },         headers: {             'x-csrftoken': csrftoken         }     });     return false; }  $('a.vote').click(function(){     var contentid = parseint(this.id.split('-')[2]):     return vote(contentid); })  }); 

any on appreciated!

notice error suggest doing get request:

page not found (404) request method: request url:    http://localhost:8000/vote/ 

i think because in index.html, using:

<a href='/vote/' id='content-vote-{{ content.id }}'>+rep</a> 

and try bind onclick on using:

$('a.vote').click(function(){     var contentid = parseint(this.id.split('-')[2]):     return vote(contentid); }) 

this $('a.vote') selector won't work, since there no <a> has class="vote". thus, onclick thing not working, either. directly hitting /vote/ using get. hence error.


Comments