django 1.2.1更新后 关于CSRF token missing or incorrect的问题
因此,如果post提交表单的html代码如下,django会抛出一个异常.
CSRF token missing or incorrect.
< div class ="commentTextArea" >
< textarea name ="content" cols ="" rows="" > </textarea>
< input name ="articleId" type ="hidden" value ="`articleObj`.`id`" />
</div>
< input name ="submit" value ="提交评论" type ="submit" />
</form>
同样在异常信息中,django给出了解决方案.
In the template, there is a
{% csrf_token %}
template tag inside each POST form that targets an internal URL.
所以html如下,在form区域内加上了{% csrf_token %}
这个标签会自动被django模板处理成一段html
加上{% csrf_token %}的HTML。
< div class ="commentTextArea" >
< textarea name ="content" cols ="" rows="" > </textarea>
< input name ="articleId" type ="hidden" value ="`articleObj`.`id`" />
</div>
< input name ="submit" value ="提交评论" type ="submit" />
</form>