pinax-project-account login redirect to dynamic url

60 views
Skip to first unread message

Daniel Kane

unread,
May 5, 2014, 11:08:27 PM5/5/14
to django...@googlegroups.com

I'm writing a web app that uses the pinax-project-account and bootstrap. When a user logs in the login view should grab the ACCOUNT_LOGIN_REDIRECT_URL and redirect the user to it. There seems to be an issue with dynamic urls though because when I do this with a static /profile/ url, there is no problem. I've traced the stacktrace to it's root which is in the account app LoginView  in account.views. It seems that is where fallback_url is being assigned the value of ACCOUNT_LOGIN_REDIRECT_URL. 


account.views

def get_success_url(self, fallback_url=None, **kwargs):

    if fallback_url is None:

        fallback_url = settings.ACCOUNT_LOGIN_REDIRECT_URL

    kwargs.setdefault("redirect_field_name", self.get_redirect_field_name())

    return default_redirect(self.request, fallback_url, **kwargs)

      

  • Below is the rest of my related code. Does anyone know how to resolve this?


settings.py

ABSOLUTE_URL_OVERRIDES = {

    "user_accounts.userprofile": lambda o: "/profile/%s/" % o.slug,

}

ACCOUNT_LOGIN_REDIRECT_URL = "profile_update"


views.py


class ProfileUpdateView(UpdateView):

    template_name = "account/profile.html"

    model = UserProfile

    context_object_name = "profile"

    slug_field = "slug"


urls.py


 url(r"^(?P<slug>)/", (ProfileUpdateView.as_view()), name="profile_update")


StackTrace


NoReverseMatch at /account/login/

Reverse for 'profile_update' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: ['profile/(?P<slug>)/']
Request Method:POST
Request URL:http://127.0.0.1:8000/account/login/
Django Version:1.6.2
Exception Type:NoReverseMatch
Exception Value:
Reverse for 'profile_update' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: ['profile/(?P<slug>)/']
Exception Location:/home/falcon/dev/tiger/env/local/lib/python2.7/site-packages/django/core/urlresolvers.py in _reverse_with_prefix, line 429
Python Executable:/home/falcon/dev/tiger/env/bin/python
Python Version:2.7.5
Python Path:
['/home/falcon/dev/tiger/tigersite',
 '/home/falcon/dev/tiger/env/src/idios',
 '/home/falcon/dev/tiger/env/lib/python2.7',
 '/home/falcon/dev/tiger/env/lib/python2.7/plat-i386-linux-gnu',
 '/home/falcon/dev/tiger/env/lib/python2.7/lib-tk',
 '/home/falcon/dev/tiger/env/lib/python2.7/lib-old',
 '/home/falcon/dev/tiger/env/lib/python2.7/lib-dynload',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-i386-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/home/falcon/dev/tiger/env/local/lib/python2.7/site-packages']
Server time:Tue, 6 May 2014 00:23:02 +0000

Traceback Switch to copy-and-paste view

  • /home/falcon/dev/tiger/env/local/lib/python2.7/site-packages/django/core/handlers/base.py in get_response
    1.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
      ...
  • /home/falcon/dev/tiger/env/local/lib/python2.7/site-packages/django/views/generic/base.py in view
    1.             return self.dispatch(request, *args, **kwargs)
      ...
  • /home/falcon/dev/tiger/env/local/lib/python2.7/site-packages/django/views/generic/base.py in dispatch
    1.         return handler(request, *args, **kwargs)
      ...
  • /home/falcon/dev/tiger/env/local/lib/python2.7/site-packages/django/views/generic/edit.py in post
    1.             return self.form_valid(form)
      ...
  • /home/falcon/dev/tiger/env/local/lib/python2.7/site-packages/account/views.py in form_valid
    1.             result=form.is_valid()
    2.         )
    3.         return super(LoginView, self).form_invalid(form)
    4.     def form_valid(self, form):
    5.         self.login_user(form)
    6.         self.after_login(form)
    1.         return redirect(self.get_success_url())
      ...
    1.     def after_login(self, form):
    2.         signals.user_logged_in.send(sender=LoginView, user=form.user, form=form)
    3.     def get_success_url(self, fallback_url=None, **kwargs):
    4.         if fallback_url is None:
  • /home/falcon/dev/tiger/env/local/lib/python2.7/site-packages/account/views.py in get_success_url
    1.     def after_login(self, form):
    2.         signals.user_logged_in.send(sender=LoginView, user=form.user, form=form)
    3.     def get_success_url(self, fallback_url=None, **kwargs):
    4.         if fallback_url is None:
    5.             fallback_url = settings.ACCOUNT_LOGIN_REDIRECT_URL
    6.         kwargs.setdefault("redirect_field_name", self.get_redirect_field_name())
    1.         return default_redirect(self.request, fallback_url, **kwargs)
      ...
    1.     def get_redirect_field_name(self):
    2.         return self.redirect_field_name
    3.     def login_user(self, form):
    4.         auth.login(self.request, form.user)
  • /home/falcon/dev/tiger/env/local/lib/python2.7/site-packages/account/utils.py in default_redirect
    1.         allowed_protocols=kwargs.get("allowed_protocols"),
    2.         allowed_host=request.get_host()
    3.     )
    4.     if next_url and is_safe(next_url):
    5.         return next_url
    6.     else:
    7.         try:
    1.             fallback_url = urlresolvers.reverse(fallback_url)
      ...
    1.         except urlresolvers.NoReverseMatch:
    2.             if callable(fallback_url):
    3.                 raise
    4.             if "/" not in fallback_url and "." not in fallback_url:
    5.                 raise
    6.         # assert the fallback URL is safe to return to caller. if it is
  • /home/falcon/dev/tiger/env/local/lib/python2.7/site-packages/django/core/urlresolvers.py in reverse
    1.     return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
      ...
  • /home/falcon/dev/tiger/env/local/lib/python2.7/site-packages/django/core/urlresolvers.py in _reverse_with_prefix
    1.                              (lookup_view_s, args, kwargs, len(patterns), patterns))
      ...
Reply all
Reply to author
Forward
0 new messages