当使用表单提交的时候,产生错误,错误信息如下:
Forbidden (403)
CSRF verification failed. Request aborted.
测试可行的解决方法(django文档—CSRF):
1.在模板的form中加入{% csrf_token %}
In any template that uses a POST form, use the csrf_token tag inside the <form> element if the form is for an internal URL, e.g.:
<form action="." method="post">{% csrf_token %}
This should not be done for POST forms that target external URLs, since that would cause the CSRF token to be leaked, leading to a vulnerability.
2.修改views.py,注意红色标记处
from django.shortcuts import render_to_response
from django.template import RequestContext
def sysconfig(request):
return render_to_response('SysConfig.html',locals(),RequestContext(request))