gpt4 book ai didi

python-3.7 - logout() 得到了一个意外的关键字参数 'next_page'

转载 作者:行者123 更新时间:2023-12-03 21:19:30 26 4
gpt4 key购买 nike

Django 2.2 中是否没有用于注销和登录的 next_page 或 template_name 参数?从 Django 1.11 升级到 Django 2.2 时,我遇到了这些错误!!

这是我的 urls.py

from django.contrib.auth import logout

url(r'^logout/$',logout, {'next_page': '/'},name='logout'),

settings.py 中的 logout_url 是
LOGOUT_URL = '/'

我不断收到此错误:
TypeError at /portal/logout/
logout() got an unexpected keyword argument 'next_page'
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 2.2
Exception Type: TypeError
Exception Value:
logout() got an unexpected keyword argument 'next_page'

登录也发生了同样的事情

网址.py
from django.conf.urls import url
from landing.views import landing_validation

app_name='landing'
urlpatterns = [
url(r'^$', landing_validation, name='landing')
]

View .py
def landing_validation(request):
login_response = login(request, template_name='landing.html')

return login_response

TypeError at /
login() got an unexpected keyword argument 'template_name'
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 2.2
Exception Type: TypeError
Exception Value:
login() got an unexpected keyword argument 'template_name'

最佳答案

如果您在迁移后仍然想知道该问题的解决方案,这里是最简单的解决方案:

settings.py添加:

LOGIN_REDIRECT_URL = 'home'
LOGOUT_REDIRECT_URL = 'home'
home指您的首页路线 name要不就
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/' # Or maybe another URL you want to set.

然后在您的 urls.py改变你的路线是这样的:
url(r'^logout$', LogoutView.as_view(),  name='logout'),
LogoutView来的是进口 from django.contrib.auth.views import LogoutView

关于python-3.7 - logout() 得到了一个意外的关键字参数 'next_page',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55799424/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com