Tanky WooRSS


10 May 2012
这篇博客是从旧博客 WordPress 迁移过来,内容可能存在转换异常。


Django’s comments framework

Example of using the built-in comments app

To get started using the comments app, follow these steps:


{\% load comments %\}

Once loaded you can use the template tags below.


{\% get_comment_count for entry as comment_count %\}.

In the above, blog.entry is the app label and (lower-cased) model name of the model class.

另外各种tags就直接看Django’s comments framework就行了。


CSRF verification failed. Request aborted


> > In general, this can occur when there is a genuine Cross Site Request Forgery, or when Django's CSRF mechanism has not been used correctly. For POST forms, you need to ensure: > > > > Your browser is accepting cookies. The view function uses RequestContext for the template, instead of Context. In the template, there is a {\% csrf_token %\} template tag inside each POST form that targets an internal URL. If you are not using CsrfViewMiddleware, then you must use csrf_protect on any views that use the csrf_token template tag, as well as those that accept the POST data. > >
> > 1、在表单Form里加上{\% csrf_token %\} > > > > 2、在Settings里的MIDDLEWARE_CLASSES增加配置:(一般默认就有) > > > > 'django.middleware.csrf.CsrfViewMiddleware', > > > > #'django.middleware.csrf.CsrfResponseMiddleware', > >
估计1.4的版本有了变化,在网上查了半天,最后还是在官方document上找到了: [传送门](https://docs.djangoproject.com/en/1.4/ref/contrib/csrf/) 它是这么处理的:
``` from django.core.context_processors import csrf from django.shortcuts import render_to_response def my_view(request): c = {} c.update(csrf(request)) # ... view code here return render_to_response("a_template.html", c) ```