我正在尝试覆盖通过 pip 安装的父类方法。但是,问题是我不确定如何调用我的重写类,以便它使用我的方法而不是父类方法。这是我试图覆盖的方法:
class OIDCAuthenticationBackend(ModelBackend):
def verify_claims(self, claims):
"""Verify the provided claims to decide if authentication should be allowed."""
# Verify claims required by default configuration
scopes = self.get_settings('OIDC_RP_SCOPES', 'openid email')
if 'email' in scopes.split():
return 'email' in claims
LOGGER.warning('Custom OIDC_RP_SCOPES defined. '
'You need to override `verify_claims` for custom claims verification.')
return True
我重写的方法是:
模型.py
from mozilla_django_oidc.auth import OIDCAuthenticationBackend
class MyOIDCAB(OIDCAuthenticationBackend):
def verify_claims(self, claims):
return True
根据我阅读的一些文档,我已经在 models.py 上写了这个,但我不确定我应该在哪里写这个。
然后尝试从我的 View 函数中调用它,如下所示:
views.py
from myapp import MyOIDCAB
但后来我得到了这个错误:
from myapp import MyOIDCAB
ImportError: cannot import name 'MyOIDCAB'
我不确定我是否以正确的方式调用它? 我的项目结构是:
myproject
myapp
templates
manage.py
在包站点中,他们在模板中这样调用它:
<a href="{% url 'oidc_authentication_init'%}">Login</a>
最佳答案
这个类在 models.py 文件中,所以你应该如何导入它:
from myapp.models import MyOIDCAB
https://stackoverflow.com/questions/57372862/
相关文章:
reactjs - 如果文本很长,React 'react-data-table-component
amazon-web-services - Alexa 智能家居技能 : Issue with de
java - Spring WebFlux : How to access Request Body
reactjs - 从 create-react-app 生成生产构建时缺少 index.html
python-3.x - 如何使用超时停止阻塞函数 subscribe.simple
vhdl - 什么是{globally|locally} static {primary|expre
wordpress - 在 Yoast 生成的 JSON-LD 模式中更改作者 @id
python - Tweepy Cursor.items() 无法按预期使用 api.retweet