views.pyCSRF令牌丢失或在Django
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
import MySQLdb
from django.shortcuts import render_to_response
from django.shortcuts import HttpResponseRedirect
from django.template.loader import get_template
from django.template import Context, Template,RequestContext
import datetime
import hashlib
from random import randint
import random
from django.views.decorators.csrf import csrf_protect, csrf_exempt
from django.template.context_processors import csrf
import requests
from django.template import RequestContext
from log.forms import *
@csrf_protect
def register(request):
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
user = User.objects.create_user(
username=form.cleaned_data['username'],
password=form.cleaned_data['password1'],
email=form.cleaned_data['email']
)
return HttpResponseRedirect('/register/success/')
else:
form = RegistrationForm()
variables = RequestContext(request, {
'form': form
})
return render_to_response(
'register.html',
variables,
)
# return render(request,"recharge.html")
def register_success(request):
return render_to_response(
'registration/success.html',
)
base.html
<form method="post" action="."> {% csrf_token %}
<table border="0">
{ form.as_table }}
</table>
<button type="submit" value="Register">Register</button>
<button type="button" onclick="window.location.href='/' ">Login</button>
</form>
不正确register.html
settings.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
我的Django的版本:1.10.4
我怎样才能解决这个问题?
是否可以发送检查或呈现HTML? –
呈现的HTML意味着你想注册html吗? –
是的请..所以我们可以帮你ü –