user_change_password()获得了意外的关键字参数'extra_context' [英] user_change_password() got an unexpected keyword argument 'extra_context'

查看:124
本文介绍了user_change_password()获得了意外的关键字参数'extra_context'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Django 3.0.7

Django 3.0.7

当我尝试在管理站点中更改密码时,我得到了

When I try to change password in admin site, I get

TypeError at /admin/auth/user/1/password/
user_change_password() got an unexpected keyword argument 'extra_context'

即我按了此表格链接:

更多详细信息

Environment:


Request Method: GET
Request URL: http://localhost:8000/admin/auth/user/1/password/

Django Version: 3.0.7
Python Version: 3.8.0
Installed Applications:
['admin_aux',
 'images.apps.ImagesConfig',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'posts',
 'sidebars',
 'general',
 'categories',
 'marketing',
 'home',
 'authors',
 'taggit',
 'cachalot',
 'django_cleanup.apps.CleanupConfig',
 'widgets',
 'code_samples',
 'hyper_links',
 'polls',
 'applications',
 'videos',
 'quotations',
 'languages',
 'people',
 'arbitrary_htmls.apps.ArbitraryHtmlsConfig']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback (most recent call last):
  File "/home/michael/PycharmProjects/pcask/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/michael/PycharmProjects/pcask/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/michael/PycharmProjects/pcask/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/michael/PycharmProjects/pcask/venv/lib/python3.8/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/home/michael/PycharmProjects/pcask/venv/lib/python3.8/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/home/michael/PycharmProjects/pcask/venv/lib/python3.8/site-packages/django/contrib/admin/sites.py", line 231, in inner
    return view(request, *args, **kwargs)
  File "/home/michael/PycharmProjects/pcask/venv/lib/python3.8/site-packages/django/utils/decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File "/home/michael/PycharmProjects/pcask/venv/lib/python3.8/site-packages/django/views/decorators/debug.py", line 76, in sensitive_post_parameters_wrapper
    return view(request, *args, **kwargs)

Exception Type: TypeError at /admin/auth/user/1/password/
Exception Value: user_change_password() got an unexpected keyword argument 'extra_context'

如何定位此问题?

推荐答案

我遇到了这个问题(尽管在Django 2.2中)。从我在向每个管理页面中添加extra_context的另一个Stack Overflow帖子中获得建议后开始。这似乎是无害的,但是破坏了更改密码提示。形成。最后,我删除了对urls.py的'extra_context'更改,并仅使用 ModelAdmin add_view和change_view方法

I had this issue (though in Django 2.2). It started after I took the advice from another Stack Overflow post on adding extra_context to every admin page. This seems harmless, but breaks the "change password" form. In the end I deleted the 'extra_context' changes to urls.py and added the extra_context ONLY to the admin forms I needed using the ModelAdmin add_view and change_view methods.

# New Layer Form
def add_view(self, request, form_url='', extra_context={}):
    extra_context['CATALOG_TECHNOLOGY'] = settings.CATALOG_TECHNOLOGY
    return super(LayerAdmin, self).add_view(request, form_url, extra_context)

# Edit Layer Form
def change_view(self, request, object_id, extra_context={}):
    extra_context['CATALOG_TECHNOLOGY'] = settings.CATALOG_TECHNOLOGY
    return super(LayerAdmin, self).change_view(request, object_id, extra_context=extra_context)

这是提交全文:


  • 中断提交
    • Breaking Commit
      • urls.py
      • urls.py
      • admin.py

      这篇关于user_change_password()获得了意外的关键字参数'extra_context'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆