相关疑难解决方法(0)

CSRF cookie未设置django ...验证失败

AoA我是Django的新手,我试图从POST获取数据,但是没有设置错误CSRF cookie,我尝试了很多通过谷歌在google和stackoverflow上找到解决方案,但是失败了

这是代码

views.py

    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)

HTML文件

<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)

python django cookies

4
推荐指数
2
解决办法
2万
查看次数

标签 统计

cookies ×1

django ×1

python ×1