我知道以前也有人问过类似的问题,但似乎没有一个与我的情况完全相同。我收到的错误如下所示:
Environment:
Request Method: GET
Request URL: http://web/login/auth0
Django Version: 1.11
Python Version: 3.5.4
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'social_django',
'cx_benchmark.apps.authentication']
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:
File "/usr/local/lib/python3.5/site-packages/django/urls/base.py" in reverse
77. extra, resolver = resolver.namespace_dict[ns]
During handling of the above exception ('social'), another exception occurred:
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
41. response = get_response(request)
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.5/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
57. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/social_django/utils.py" in wrapper
37. uri = reverse(redirect_uri, args=(backend,))
File "/usr/local/lib/python3.5/site-packages/django/urls/base.py" in reverse
87. raise NoReverseMatch("%s is not a registered namespace" % key)
Exception Type: NoReverseMatch at /login/auth0
Exception Value: 'social' is not a registered namespace我的应用程序是Dockerized的,我正在尝试集成Auth0和social_django。我在我的堆栈中使用了nginx、gunicorn和postgres。我主要遵循以下教程来开始运行:https://auth0.com/docs/quickstart/webapp/django
我在我的主设置文件中安装了social_django和子应用程序authentication:
# /src/my_app/settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'social_django',
'my_app.apps.authentication',
]我的Auth0集成设置如下所示:
# /src/my_app/settings.py
SOCIAL_AUTH_TRAILING_SLASH = False
SOCIAL_AUTH_AUTH0_DOMAIN = '[hidden]'
SOCIAL_AUTH_AUTH0_KEY = '[hidden]'
SOCIAL_AUTH_AUTH0_SECRET = '[hidden]'
SOCIAL_AUTH_AUTH0_SCOPE = [
'openid',
'profile'
]
AUTHENTICATION_BACKENDS = {
'my_app.apps.authentication.auth0backend.Auth0',
'django.contrib.auth.backends.ModelBackend'
}
LOGIN_URL = "/login/auth0"
LOGIN_REDIRECT_URL = "/dashboard"
LOGOUT_REDIRECT_URL = "/"我的主应用程序的urls.py如下所示:
# /src/my_app/urls.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('my_app.apps.authentication.urls', namespace='authentication')),
]身份验证应用程序的urls.py如下所示:
# /src/my_app/apps/authentication/urls.py
from django.conf.urls import include, url
from . import views
app_name = 'authentication'
urlpatterns = [
url('^$', views.index),
url(r'^dashboard', views.dashboard),
url(r'^', include('django.contrib.auth.urls', namespace='auth')),
url(r'^', include('social_django.urls', namespace='social')),
]当我构建Docker镜像,运行它并访问/login/auth0时,我得到了上述错误。
我正在使用:
certifi (2017.7.27.1)
chardet (3.0.4)
defusedxml (0.5.0)
Django (1.11) # <---
ecdsa (0.13)
future (0.16.0)
gunicorn (19.6.0)
idna (2.6)
oauthlib (2.0.6)
pip (9.0.1)
psycopg2 (2.6.2)
pycrypto (2.6.1)
PyJWT (1.5.3)
python-jose (1.4.0)
python3-openid (3.1.0)
requests (2.18.4)
requests-oauthlib (0.8.0)
setuptools (36.6.0)
six (1.11.0)
social-auth-app-django (2.0.0) # <---
social-auth-core (1.5.0)
urllib3 (1.22)
wheel (0.30.0)有什么建议吗?谢谢!
发布于 2018-05-26 03:59:30
尝试将以下内容添加到/src/my_app/apps/authentication/urls.py
SOCIAL_AUTH_URL_NAMESPACE = "my_app:social"发布于 2017-11-06 17:54:12
如果这是有意义,那么您使用的是两个基本url。django.contrib.auth.urls和social_django.urls具有相同的url。我认为你需要改变其中的任何一个。如果我错了,请忽略。如果有帮助,请告诉我。谢谢。
https://stackoverflow.com/questions/47103063
复制相似问题