我使用的是 DJango 2.2.6
个人资料应用
app_name = 'myprofileapp'
urlpatterns = [
path('profile', accountController.as_view(), name='account')
]
身份验证应用
app_name = 'authapp'
urlpatterns = [
path('login', loginController.as_view(), name='login')
]
以下是登录用户的代码。如果登录成功,则发送到个人资料页面。
class loginController(View):
def post(self, request):
username = request.POST.get('username')
password = request.POST.get('password')
userobj = authenticate(username = username, password = password)
if(userobj == None):
return HttpResponse("Not Found")
else:
login(request, userobj)
return redirect('profile')
在这段代码login(request, userobj)
之后,如果我写return render(request, 'profile.html')
,那么url仍然是登录状态。
当我写return redirect('profile')
时,它说
Reverse for 'profile' not found. 'profile' is not a valid view function or pattern name.
我错过了什么吗?
最佳答案
path('profile', accountController.as_view(), name='profile')
将name='account'
更改为name='profile'
关于django - 从一个页面重定向到另一页面时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58789918/