视图.py
from django.shortcuts import render_to_response
from django.core.context_processors import csrf
def home(request):
c = {}
c.update(csrf(request))
if request.method == "POST":
username = request.POST.get("username", '')
password = request.POST.get("password", '')
return render_to_response("login_home.html", {"username":username, "password":password})
else:
return render_to_response("login_home.html")
login_home.html
{% extends "base.html" %}
{% block page %}
{{ name }}
<form action = "/blog/home/" method = "POST">{% csrf_token %}
<input type = "text" name = "username" placeholder = "username">
<input type = "text" name = "password" placeholder = "password">
<input type = "submit">
</form>
{{ username }}
{{ password }}
{% endblock %}
网址.py
from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
url(r'^home/$', 'blog.views.home'),
)
^^这是我的文件。问题是提交表单后出现的错误:
Forbidden (403)
CSRF verification failed. Request aborted.
我不确定我忘记或错过了什么。我猜它在视图函数中的某个地方。有人可以指出我缺少的一点吗?
谢谢你的帮助。