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'
登录也发生了同样的事情
urls.py
from django.conf.urls import url
from landing.views import landing_validation
app_name='landing'
urlpatterns = [
url(r'^$', landing_validation, name='landing')
]
views.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'
答案 0 :(得分:3)
如果您仍然想在迁移后解决该问题,那么这里是最简单的解决方法:
在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