Django 2 新手。我已经检查了所有与此错误相关的早期帖子,但找不到我的错误。以下是详细信息:项目-learning_users;应用程序 - basic_app。有 4 个模板 - base.html、index.html、login.html、注册。html。views.pyfrom basic_app.forms import UserForm, UserProfileInfoFormfrom django.contrib.auth import authenticate, login, logoutfrom django.http import HttpResponse, HttpResponseRedirectfrom django.urls import reversefrom django.contrib.auth.decorators import login_required# Viewsdef index(request): return render(request, 'basic_app/index.html')@login_requireddef special(request): return HttpResponse("You are logged in, Nice !")@login_requireddef 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})
1 回答
当年话下
TA贡献1890条经验 获得超9个赞
在你的login.html
:
<form method="post" action="{% url 'basic_app:login' %}" >
在你的base.html
:
<li><a class="nav-link" href="{% url 'basic_app:login' %}">Login</a></li>
例如,您的名字是:login
在您的urls.py
:
path('user_login/', views.user_login, name='login')
添加回答
举报
0/150
提交
取消