1

My Django application already has an app called account. Does it mean that it is ABSOLUTELY impossible to use django all-auth because of the name conflict? Due to the existing data, the app account cannot be renamed.

settings.py:

INSTALLED_APPS = [
    ...
    'account',
    ...

    # For allauth:
    'django.contrib.sites',
    'allauth',
    'allauth.account',    # Name conflict
    ...

If so, is there a good alternative?


  1. 2-14

Per solarissmoke's suggestion. Where should I put the new app and what is it name? Is it something like this (Of course, it is wrong)?

my_project/account/apps.py:

import allauth.account
from django.apps import AppConfig


class AccountConfig(AppConfig):
    name = 'account'


class AllAuthAccountConfig(allauth.account):
    name = 'allauth.account'
    label = 'allauth_account'  # Change this
    verbose_name = 'aullauth_account'
David Buck
  • 3,752
  • 35
  • 31
  • 35
Randy Tang
  • 4,283
  • 12
  • 54
  • 112

2 Answers2

3

This is a known problem with django-allauth.

You can work around it by changing your own app to use a different app label. In your app's AppConfig:

class AccountConfig(AppConfig):
    name = 'my_project.apps.account'
    label = 'my_project_account'  # Change this
    verbose_name = 'account'

And refer to this app config in your INSTALLED_APPS, e.g.,

INSTALLED_APPS = [
    ...
    'account.apps.AccountConfig',
    ...

    'allauth',
    'allauth.account',
    ...

Which should now work because the app labels are unique. Note that the only issue with this is that database tables names for your account app will have to change so as not to conflict with the allauth app - this will require some data migrations (if on an established project) or creation of fresh migrations (if on a project where you can afford to clobber the database).

You can also do this with the allauth.account app if that's easier - just create a new app config anywhere in your project, e.g.,

my_project/allauth_apps/apps.py (make sure to also create __init__.py in this new directory):

class AllAuthAccountConfig(allauth.account):
    name = 'allauth.account'
    label = 'allauth_account'  # Change this
    verbose_name = 'aullauth_account'

And then in your INSTALLED_APPS replace account with my_project.allauth_apps.apps.AllAuthAccountConfig. As above, this changes the database table names.

solarissmoke
  • 30,039
  • 14
  • 71
  • 73
  • How about renaming allauth's `account` ? – Randy Tang Feb 13 '20 at 01:27
  • 1
    You should be able to do that too - just create a new app config to subclass the `allauth.account` app config, give it a new label, and use that in place of `account`. – solarissmoke Feb 13 '20 at 03:14
  • I've edited the answer with details of how to subclass the allauth app. – solarissmoke Feb 14 '20 at 06:59
  • Did what you suggested: 1) under `my_project`, add `allauth_apps` dir with a `__init__.py` file in it. 2) Replace `allauth.account` with `allauth_apps.apps.AllAuthAccountConfig` (should remove `my_project`, right?). 3) In `allauth_apps` dir add an `apps.py` file with the content you described. However, now I got `module.__init__() takes at most 2 arguments (3 given)` error message for the line `class AllAuthAccountConfig(allauth.account): ` (In that file, I should `import allauth.account, right?) – Randy Tang Feb 14 '20 at 08:04
0

you need to fork the git on your own and change the label

  1. fork the source code from https://github.com/pennersr/django-allauth/
  2. add unique label such as allauthaccount to app in django-allauth/allauth/account/apps.py on your own forked git
  3. commit
  4. add following line to your requirements.txt -e git+https://github.com/andylee0213/django-allauth#egg=django_allauth
  5. do "pip install -r requirements.txt and pip freeze > requirements.txt" and check github link is still in requirements.txt

but my suggestion is, instead of not receiving updates and going through all this pain, just use other auth libraries. There are many other libraries that does not depend on all auth. check https://medium.com/codex/django-allauth-vs-dj-rest-auth-vs-python-social-auth-vs-drf-social-oauth2-ef7d50f92d16

andylee
  • 255
  • 2
  • 6