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:POSTRequest URL:http://127.0.0.1:8000/account/login/Django
Version:1.6.2Exception Type:NoReverseMatchException 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 429Python Executable:
/home/falcon/dev/tiger/env/bin/pythonPython Version:2.7.5Python 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<http://127.0.0.1:8000/account/login/#>
-
/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)
...
▶ Local vars <http://127.0.0.1:8000/account/login/#>
-
/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)
...
▶ Local vars <http://127.0.0.1:8000/account/login/#>
-
/home/falcon/dev/tiger/env/local/lib/python2.7/site-packages/django/views/generic/base.py
in dispatch
1.
return handler(request, *args, **kwargs)
...
▶ Local vars <http://127.0.0.1:8000/account/login/#>
-
/home/falcon/dev/tiger/env/local/lib/python2.7/site-packages/django/views/generic/edit.py
in post
1.
return self.form_valid(form)
...
▶ Local vars <http://127.0.0.1:8000/account/login/#>
-
/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.
5.
def form_valid(self, form):
6.
self.login_user(form)
7.
self.after_login(form)
1.
return redirect(self.get_success_url())
...
1.
2.
def after_login(self, form):
3.
signals.user_logged_in.send(sender=LoginView, user=form.user,
form=form)
4.
5.
def get_success_url(self, fallback_url=None, **kwargs):
6.
if fallback_url is None:
▶ Local vars <http://127.0.0.1:8000/account/login/#>
-
/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.
4.
def get_success_url(self, fallback_url=None, **kwargs):
5.
if fallback_url is None:
6.
fallback_url = settings.ACCOUNT_LOGIN_REDIRECT_URL
7.
kwargs.setdefault("redirect_field_name",
self.get_redirect_field_name())
1.
return default_redirect(self.request, fallback_url, **kwargs)
...
1.
2.
def get_redirect_field_name(self):
3.
return self.redirect_field_name
4.
5.
def login_user(self, form):
6.
auth.login(self.request, form.user)
▶ Local vars <http://127.0.0.1:8000/account/login/#>
-
/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
▶ Local vars <http://127.0.0.1:8000/account/login/#>
-
/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))
...
▶ Local vars <http://127.0.0.1:8000/account/login/#>
-
/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))
...
▶ Local vars <http://127.0.0.1:8000/account/login/#>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/981c67d3-48a9-4f2a-af0e-f1b74ace3531%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.