Django 2 新手。我已经检查了所有与此错误相关的早期帖子,但找不到我的错误。以下是详细信息:项目-learning_users;应用程序 - basic_app。有 4 个模板 - base.html、index.html、login.html、注册。html。
views.py
from basic_app.forms import UserForm, UserProfileInfoForm
from django.contrib.auth import authenticate, login, logout
from django.http import HttpResponse, HttpResponseRedirect
from django.urls import reverse
from django.contrib.auth.decorators import login_required
# Views
def index(request):
return render(request, 'basic_app/index.html')
@login_required
def special(request):
return HttpResponse("You are logged in, Nice !")
@login_required
def user_logout(request):
logout(request)
return HttpResponseRedirect(reverse('index'))
def register(request):
registered = False
if request.method == "POST":
user_form = UserForm(data=request.POST)
profile_form = UserProfileInfoForm(data=request.POST)
if user_form.is_valid and profile_form.is_valid:
user = user_form.save()
user.set_password(user.password)
user.save()
profile = profile_form.save(commit=False)
profile.user = user
if 'profile_pic' in request.FILES:
profile.profile_pic = request.FILES['profile_pic']
profile.save()
registered = True
else:
print(user_form.errors, profile_form.errors)
else:
user_form = UserForm()
profile_form = UserProfileInfoForm()
return render(request, 'basic_app/registration.html',
{'user_form':user_form,
'profile_form':profile_form,
'registered':registered})
当年话下
相关分类