AoA我是Django的新手,我试图从POST获取数据,但是没有设置错误CSRF cookie,我尝试了很多通过谷歌在google和stackoverflow上找到解决方案,但是失败了
这是代码
from django.http import HttpResponse
from django.template.loader import get_template
from django.template import Context
from django.template import RequestContext
from django.core.context_processors import csrf
from django.shortcuts import render_to_response
def search_Post(request):
if request.method == 'POST':
c = {}
c.update(csrf(request))
# ... view code here
return render_to_response("search.html", c)
def search_Page(request):
name='Awais you have visited my website :P'
t = get_template('search.html')
html = t.render(Context({'name':name}))
return HttpResponse(html)
Run Code Online (Sandbox Code Playgroud)
<p>
{{ name }}
<form method="POST" action="/save/">
{% csrf_token %}
<textarea name="content" rows="20" cols="60">{{content}}</textarea><br>
<input type="submit" …Run Code Online (Sandbox Code Playgroud)