Django休息AllAuth:ImportError at / auth / registration /没有名为account.adapter的模块

时间:2015-08-07 12:47:17

标签: python django rest django-allauth

我试图制作一个自定义适配器来编辑allauth.account.adapter中的send_mail函数(遵循此说明http://django-allauth.readthedocs.org/en/latest/advanced.html#custom-redirects),但是当我执行该函数时它无法找到帐户模块。这是追溯:

Environment:
Request Method: POST
Request URL: http://localhost:8000/auth/registration/

Django Version: 1.8.3
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.sites',
 'api',
 'rest_framework',
 'rest_framework_swagger',
 'rest_framework.authtoken',
 'rest_auth',
 'allauth',
 'allauth.account',
 'allauth.socialaccount',
 'rest_auth.registration',
 'djrill')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware')


Traceback:
File "/home/lccot/Documents/cursoslccbackend/env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/lccot/Documents/cursoslccbackend/env/local/lib/python2.7/site-packages/django/views/decorators/csrf.py" in wrapped_view
  58.         return view_func(*args, **kwargs)
File "/home/lccot/Documents/cursoslccbackend/env/local/lib/python2.7/site-packages/django/views/generic/base.py" in view
  71.             return self.dispatch(request, *args, **kwargs)
File "/home/lccot/Documents/cursoslccbackend/env/local/lib/python2.7/site-packages/rest_framework/views.py" in dispatch
  456.             response = self.handle_exception(exc)
File "/home/lccot/Documents/cursoslccbackend/env/local/lib/python2.7/site-packages/rest_framework/views.py" in dispatch
  453.             response = handler(request, *args, **kwargs)
File "/home/lccot/Documents/cursoslccbackend/env/local/lib/python2.7/site-packages/rest_auth/registration/views.py" in post
  43.         if self.form.is_valid():
File "/home/lccot/Documents/cursoslccbackend/env/local/lib/python2.7/site-packages/django/forms/forms.py" in is_valid
  184.         return self.is_bound and not self.errors
File "/home/lccot/Documents/cursoslccbackend/env/local/lib/python2.7/site-packages/django/forms/forms.py" in errors
  176.             self.full_clean()
File "/home/lccot/Documents/cursoslccbackend/env/local/lib/python2.7/site-packages/django/forms/forms.py" in full_clean
  392.         self._clean_fields()
File "/home/lccot/Documents/cursoslccbackend/env/local/lib/python2.7/site-packages/django/forms/forms.py" in _clean_fields
  410.                     value = getattr(self, 'clean_%s' % name)()
File "/home/lccot/Documents/cursoslccbackend/env/local/lib/python2.7/site-packages/allauth/account/forms.py" in clean_username
  252.         value = get_adapter().clean_username(value)
File "/home/lccot/Documents/cursoslccbackend/env/local/lib/python2.7/site-packages/allauth/account/adapter.py" in get_adapter
  359.     return import_attribute(app_settings.ADAPTER)()
File "/home/lccot/Documents/cursoslccbackend/env/local/lib/python2.7/site-packages/allauth/utils.py" in import_attribute
  119.     ret = getattr(importlib.import_module(pkg), attr)
File "/usr/lib/python2.7/importlib/__init__.py" in import_module
  37.     __import__(name)
File "/home/lccot/Documents/cursoslccbackend/cursoslccbackend/cursoslccbackend/adapters/allauth.py" in <module>
  2. from allauth.account.adapter import DefaultAccountAdapter

Exception Type: ImportError at /auth/registration/
Exception Value: No module named account.adapter

这是自定义适配器文件(allauth.py):

from django.conf import settings
from allauth.account.adapter import DefaultAccountAdapter

class CustomAdapter(DefaultAccountAdapter):

    def send_mail(self, template_prefix, email, context):
        msg = self.render_mail(template_prefix, email, context)
        msg.send()

1 个答案:

答案 0 :(得分:0)

问题出在自定义适配器文件的名称中。它被命名为&#34; allauth.py&#34;。只需将文件重命名为其他内容即可。

这是因为python模块按以下顺序导入搜索:

  • 包含输入脚本(或当前目录)的目录。
  • PYTHONPATH(目录名列表,语法与
  • 相同
  • shell变量PATH)。依赖于安装的默认值。