I'm having trouble registering a vote with registering a vote with django-voting: https://github.com/brosner/django-voting
I'm trying to technically upvote a comment object. Thus adding to it's score.
This is what I have so far:
Template:
<form method="POST" action="/comments/{{ comment.id }}/up/vote/">
{% csrf_token %}
<button type="submit">Thumbs up!</button>
</form>
urls
widget_dict = {
'model': Comment,
'template_object_name': 'comment',
'allow_xmlhttprequest': True,
}
#users can comment on event objects, And VOTE on comments
urlpatterns = patterns('',
url(r'^$', 'event.views.index'),
url(r'^(?P<id>\d+)/$', 'event.views.detail'),
url(r'^comments/(?P<object_id>\d+)/(?P<direction>up|down|clear)/vote/?$', vote_on_object, widget_dict),
)
With this I get directed to a 404.
The docs give an example of :
from django.conf.urls.defaults import *
from voting.views import vote_on_object
from shop.apps.products.models import Widget
widget_dict = {
'model': Widget,
'template_object_name': 'widget',
'allow_xmlhttprequest': True,
}
urlpatterns = patterns('',
(r'^widgets/(?P<object_id>\d+)/(?P<direction>up|down|clear)vote/?$', vote_on_object, widget_dict),
)
Also, I can't add votes through the admin?
I have no idea what widget_dict actually is. I'm just trying to have the form post to vote_on_object
. Has anyone successfully posted a vote? If so, what am I doing wrong? Thanks for your help in advance.
I think you have a typo and you're forgetting a '/'
your url in the form should be '/widgets/{{ comment.id }}/up/vote/'
or the pattern should start with comments
And then the pattern, you forget a slash:
(?P<direction>up|down|clear)vote/?$
should be
(?P<direction>up|down|clear)/vote/?$
If you want to check routing, you can do from the shell
import re
re.match(r'^widgets/(?P<object_id>\d+)/(?P<direction>up|down|clear)/vote/?$', '/comment/1/up/vote/')
and see it works