Chr*_* B. 6 django django-registration django-users django-allauth
我注意到通过django-allauth模板查看了一个signup_closed.html用户可以被重定向到用户注册关闭或禁用时.熟悉该模块的人是否知道是否有预先配置的设置可以在settings.py中设置以通过现有的社交应用程序关闭新的用户注册?或者我需要自己配置?我已经阅读了allauth的完整文档,我没有看到任何提及它.谢谢.
没有预先配置的设置,但很容易进行设置(这就是我所做的)。
# settings.py
# Point to custom account adapter.
ACCOUNT_ADAPTER = 'myproject.myapp.adapter.CustomAccountAdapter'
# A custom variable we created to tell the CustomAccountAdapter whether to
# allow signups.
ACCOUNT_ALLOW_SIGNUPS = False
Run Code Online (Sandbox Code Playgroud)
# myapp/adapter.py
from django.conf import settings
from allauth.account.adapter import DefaultAccountAdapter
class CustomAccountAdapter(DefaultAccountAdapter):
def is_open_for_signup(self, request):
"""
Whether to allow sign ups.
"""
allow_signups = super(
CustomAccountAdapter, self).is_open_for_signup(request)
# Override with setting, otherwise default to super.
return getattr(settings, 'ACCOUNT_ALLOW_SIGNUPS', allow_signups)
Run Code Online (Sandbox Code Playgroud)
这是灵活的,特别是如果您有多个环境(例如登台)并且希望在将其设置为生产环境之前允许用户在登台中注册。
小智 5
更多信息请访问http://django-allauth.readthedocs.io/en/latest/advanced.html#custom-redirects。
您需要子类化allauth.account.adapter.DefaultAccountAdapter以覆盖is_open_for_signup,然后设置ACCOUNT_ADAPTER为您的类settings.py
| 归档时间: |
|
| 查看次数: |
1824 次 |
| 最近记录: |