Проблемы с добавлением social_django в трясогузку - PullRequest
0 голосов
/ 25 июня 2019

Я добавил этот URL в /projectname/urls.py:

url(r'social-auth/', include('social_django.urls', namespace='social')),

И затем я добавил это в шаблон домашней страницы трясогузки (как показано в примере документов ):

   {% for name in social_auth.backends.oauth %}
      <li><a rel="nofollow" href="{% url "socialauth_begin" %}">{{ name|title }}</a></li>
   {% endfor %}

Но я ничего не видел в шаблоне, но я добавил

AUTHENTICATION_BACKENDS = (
 'social_core.backends.open_id.OpenIdAuth',  # for Google authentication
 'social_core.backends.google.GoogleOpenId',  # for Google authentication
 'social_core.backends.google.GoogleOAuth2',  # for Google authentication
 'django.contrib.auth.backends.ModelBackend',
)

в настройках / base.py.

Так как я могу реализовать аутентификацию в Wagtail CMS, чтобы пользователи могли добавлять комментарии в блог?

EDIT:

Вот как выглядит моя настройка ШАБЛОНОВ:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(PROJECT_DIR, 'templates'),
        ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'social_django.context_processors.backends',
                'social_django.context_processors.login_redirect',
                'social_auth.context_processors.social_auth_by_type_backends',
            ],
        },
    },
]

И моя домашняя страница теперь показывает ошибку:

Internal Server Error: /
Traceback (most recent call last):
  File "/home/dolidod/.local/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/dolidod/.local/lib/python3.7/site-packages/django/core/handlers/base.py", line 145, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/dolidod/.local/lib/python3.7/site-packages/django/core/handlers/base.py", line 143, in _get_response
    response = response.render()
  File "/home/dolidod/.local/lib/python3.7/site-packages/django/template/response.py", line 106, in render
    self.content = self.rendered_content
  File "/home/dolidod/.local/lib/python3.7/site-packages/django/template/response.py", line 83, in rendered_content
    content = template.render(context, self._request)
  File "/home/dolidod/.local/lib/python3.7/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "/home/dolidod/.local/lib/python3.7/site-packages/django/template/base.py", line 169, in render
    with context.bind_template(self):
  File "/usr/lib/python3.7/contextlib.py", line 112, in __enter__
    return next(self.gen)
  File "/home/dolidod/.local/lib/python3.7/site-packages/django/template/context.py", line 242, in bind_template
    processors = (template.engine.template_context_processors +
  File "/home/dolidod/.local/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/dolidod/.local/lib/python3.7/site-packages/django/template/engine.py", line 85, in template_context_processors
    return tuple(import_string(path) for path in context_processors)
  File "/home/dolidod/.local/lib/python3.7/site-packages/django/template/engine.py", line 85, in <genexpr>
    return tuple(import_string(path) for path in context_processors)
  File "/home/dolidod/.local/lib/python3.7/site-packages/django/utils/module_loading.py", line 17, in import_string
    module = import_module(module_path)
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'social_auth'
[26/Jun/2019 15:04:39] "GET / HTTP/1.1" 500 124661
^[[15~Internal Server Error: /
Traceback (most recent call last):
  File "/home/dolidod/.local/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/dolidod/.local/lib/python3.7/site-packages/django/core/handlers/base.py", line 145, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/dolidod/.local/lib/python3.7/site-packages/django/core/handlers/base.py", line 143, in _get_response
    response = response.render()
  File "/home/dolidod/.local/lib/python3.7/site-packages/django/template/response.py", line 106, in render
    self.content = self.rendered_content
  File "/home/dolidod/.local/lib/python3.7/site-packages/django/template/response.py", line 83, in rendered_content
    content = template.render(context, self._request)
  File "/home/dolidod/.local/lib/python3.7/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "/home/dolidod/.local/lib/python3.7/site-packages/django/template/base.py", line 169, in render
    with context.bind_template(self):
  File "/usr/lib/python3.7/contextlib.py", line 112, in __enter__
    return next(self.gen)
  File "/home/dolidod/.local/lib/python3.7/site-packages/django/template/context.py", line 242, in bind_template
    processors = (template.engine.template_context_processors +
  File "/home/dolidod/.local/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/dolidod/.local/lib/python3.7/site-packages/django/template/engine.py", line 85, in template_context_processors
    return tuple(import_string(path) for path in context_processors)
  File "/home/dolidod/.local/lib/python3.7/site-packages/django/template/engine.py", line 85, in <genexpr>
    return tuple(import_string(path) for path in context_processors)
  File "/home/dolidod/.local/lib/python3.7/site-packages/django/utils/module_loading.py", line 17, in import_string
    module = import_module(module_path)
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'social_auth'
[26/Jun/2019 15:04:45] "GET / HTTP/1.1" 500 124661

1 Ответ

1 голос
/ 26 июня 2019

Переменная social_auth определяется процессором контекста шаблона: https://github.com/omab/django-social-auth/blob/master/doc/configuration.rst#template-context-processors

Похоже, что пример приложения использует 'social_auth.context_processors.social_auth_by_type_backends', поэтому вам, вероятно, следует добавить это кнастройки вашего проекта TEMPLATE_CONTEXT_PROCESSORS.

...