django post方法不能提交

def login(request):
    if request.method == 'GET':
        c = {}
        c.update(csrf(request))
        return render_to_response("login.html", c)
    elif request.method == 'POST' and 'username' in request.POST and request.POST['username']:
        c = {'name' :'username'}
        response = render_to_response("index.html")
        response.set_cookie("username", request.POST['username'])
        return response
    else:
        return Http404

step one:

在提交post 表单前,csrf_token 必须有值。

{% csrf_token %}
posted @ 2015-12-22 09:36  pyfreshman  阅读(972)  评论(0编辑  收藏  举报