I'm trying to make a custom adapter to edit the send_mail function in allauth.account.adapter (following this instructions http://django-allauth.readthedocs.org/en/latest/advanced.html#custom-redirects), but when I execute the function It can't find the account module. This is the traceback:
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
This is the custom adapter file (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()
The issue is in the name of the custom adapter file. It's named "allauth.py". Just rename the file to something else.
This happens because the python module import search work in this order: