我正在尝试使用django-hitcount模块来保存不同用户访问教程的次数。
该模块已按照博客中的说明正确安装。hitcount 模板标签似乎返回了正确的结果。
<script type="text/javascript">
$(document).ready(function() {
{% get_hit_count_javascript for tut_contents %}
});
</script>
<script type="text/javascript">
// returns
$(document).ready(function() {
$.post( '/tutorial/ajax/hit/',
{ hitcount_pk : '1' },
function(data, status) {
if (data.status == 'error') {
// do something for error?
}
},
'json');
});
</script>
我的网址.py
from django.conf.urls import patterns
from hitcount.views import update_hit_count_ajax
from django.conf.urls import url
urlpatterns = patterns('tutorial.views',
(r'^$', 'root'),
# Hitcount url to save hits on tutorial entity
url(r'^ajax/hit/$', update_hit_count_ajax, name='hitcount_update_ajax'),
)
问题是当我检查我的调试器时。
Failed to load resource: the server responded with a status of 403 (FORBIDDEN)
POST http://waaave.com.dev:8000/tutorial/ajax/hit/ 403 (FORBIDDEN)
(这可能是 hitcount_hit 表中没有保存任何内容的原因)