Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django-allauth: Can't Reverse Match url

I have installed Django-allauth and followed every step carefully:

Settings.py

TEMPLATE_CONTEXT_PROCESSORS = (
    "django.contrib.auth.context_processors.auth",
    'django.core.context_processors.request',
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    "django.core.context_processors.static",
    "django.core.context_processors.tz",
    "django.contrib.messages.context_processors.messages",    
    "allauth.account.context_processors.account",
    "allauth.socialaccount.context_processors.socialaccount",
)

AUTHENTICATION_BACKENDS =  (
    'django.contrib.auth.backends.ModelBackend',    
    "allauth.account.auth_backends.AuthenticationBackend",
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',    
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.google',
    ...
)

ACCOUNT_AUTHENTICATION_METHOD="username_email"

url.py

(r'^accounts/', include('allauth.urls')),

However when running it I get a 404 at http://localhost:8000/accounts/

I tried to reverse match it manually:

./manage.py shell
from allauth.socialaccount.providers.google.urls import *

Works ok.

./manage.py shell
from django.core.urlresolvers import reverse
reverse('/accounts/google/login/')

However this one fails:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/kave/vc/cb-env/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 476, in reverse
    return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
  File "/home/kave/vc/cb-env/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 396, in _reverse_with_prefix
    "arguments '%s' not found." % (lookup_view_s, args, kwargs))
NoReverseMatch: Reverse for '/accounts/google/login/' with arguments '()' and keyword arguments '{}' not found.

I have installed it correctly inside the virtual-env. What could have gone wrong? Or is that a bug?

like image 358
Houman Avatar asked Oct 19 '25 10:10

Houman


2 Answers

When you use reverse you should be passing along the view name, not the view url. In case of Google, that would be reverse("google_login"). That explains your NoReverseMatch

However I still get 404 at http://localhost:8000/accounts/ any idea what could be wrong?

/accounts/ is simply not a valid URL, so the 404 is correct. Use /accounts/login/

like image 167
pennersr Avatar answered Oct 22 '25 10:10

pennersr


Allauth url names are like so: account_login, account_logout, account_change_password, ..

like image 40
mirek Avatar answered Oct 22 '25 09:10

mirek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!