TypeError: login() got an unexpected keyword argument ‘extra_context’
Django2.1.9+python3.7+Xadmin(github原码)
几乎全场bug,跟随网友们的指导一个个解决 卡在
TypeError:
login() got an unexpected keyword argument ‘extra_context’
Error location File"/Users/user/Desktop/DjangoStudy/extra_app/xadmin/views/website.py", line 65, in get return login(request, **defaults)
登入登出界面都会出现这个Error,上方法:
因为之前有用过pip下载版本的xadmin2 当时没有出现这个Error,然后就去那个版本的包里看了一下xadmin/views/website.py文件 发现确实有很多不一样,而且不会报错,厉害的同学可以仔细看看,新手可以简单粗暴直接将Website.py文件替换掉
不会报错的webiste.py文件如下
from future import absolute_import
from django.utils.translation import ugettext as _
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.views.decorators.cache import never_cache
from django.contrib.auth.views import LoginView as login
from django.contrib.auth.views import LogoutView as logout
from django.http import HttpResponse
from .base import BaseAdminView, filter_hook
from .dashboard import Dashboard
from xadmin.forms import AdminAuthenticationForm
from xadmin.models import UserSettings
from xadmin.layout import FormHelper
class IndexView(Dashboard):
title = _(“Main Dashboard”)
icon = “fa fa-dashboard”
def get_page_id(self):
return 'home'
class UserSettingView(BaseAdminView):
@never_cache
def post(self, request):
key = request.POST['key']
val = request.POST['value']
us, created = UserSettings.objects.get_or_create(
user=self.user, key=key)
us.value = val
us.save()
return HttpResponse('')
class LoginView(BaseAdminView):
title = _("Please Login")
login_form = None
login_template = None
@filter_hook
def update_params(self, defaults):
pass
@never_cache
def get(self, request, *args, **kwargs):
context = self.get_context()
helper = FormHelper()
helper.form_tag = False
helper.include_media = False
context.update({
'title': self.title,
'helper': helper,
'app_path': request.get_full_path(),
REDIRECT_FIELD_NAME: request.get_full_path(),
})
defaults = {
'extra_context': context,
# 'current_app': self.admin_site.name,
'authentication_form': self.login_form or AdminAuthenticationForm,
'template_name': self.login_template or 'xadmin/views/login.html',
}
self.update_params(defaults)
# return login(request, **defaults)
return login.as_view(**defaults)(request)
@never_cache
def post(self, request, *args, **kwargs):
return self.get(request)
class LogoutView(BaseAdminView):
logout_template = None
need_site_permission = False
@filter_hook
def update_params(self, defaults):
pass
@never_cache
def get(self, request, *args, **kwargs):
context = self.get_context()
defaults = {
'extra_context': context,
# 'current_app': self.admin_site.name,
'template_name': self.logout_template or 'xadmin/views/logged_out.html',
}
if self.logout_template is not None:
defaults['template_name'] = self.logout_template
self.update_params(defaults)
# return logout(request, **defaults)
return logout.as_view(**defaults)(request)
@never_cache
def post(self, request, *args, **kwargs):
return self.get(request)
暂时解决,后续再看