Problems With Django Hitcount Module
I'm trying to use the django-hitcount module to save the number of times a tutorial is accessed by different users. The module is correctly installed as explained in the blog. The
Solution 1:
Since you are sending the request as POST and getting a 403 Forbidden, I'm going to guess this is a problem with csrf token, which in django is required in every POST request.
Solving it is easy. Just copy the getCookie function from the documentation and either send it with the header like they explain, or simply add it to your data in the request like this:
$(document).ready(function() {
$.post( '/tutorial/ajax/hit/',
{ 'hitcount_pk' : '1',
'csrfmiddlewaretoken': getCookie('csrftoken') },
function(data, status) {
if (data.status == 'error') {
// do something for error?
}
},
'json');
});
Post a Comment for "Problems With Django Hitcount Module"