Admin login redirect problem

2,041 views
Skip to first unread message

asdfg

unread,
Feb 25, 2011, 8:05:13 AM2/25/11
to Mezzanine Users
When I log into admin, I'm getting redirected to /accounts/profile/
(for which a template doesn't exist). How can I change it to redirect
to the dashboard?

asdfg

unread,
Feb 25, 2011, 10:13:09 AM2/25/11
to Mezzanine Users
OK, I figured out I can change this by adding the following in
settings.py: LOGIN_REDIRECT_URL = '/admin/'
Shouldn't this be the default though?

Tom von Schwerdtner

unread,
Feb 26, 2011, 3:51:50 PM2/26/11
to mezzani...@googlegroups.com
I'm guessing this is an issue with the Mezzanine admin login form as the Django admin login will (apparently) normally ignore the LOGIN_REDIRECT_URL setting as it is intended for user-based login and not admin-based login.

Michał Oleniec

unread,
Feb 26, 2011, 5:36:42 PM2/26/11
to mezzani...@googlegroups.com
Hi,

I've noticed another problem which falls into topic raised by Tom

Mezzanine changed the login stuff and is using Django login somewhere here I think

On my site running Mezzanine I've got:
  • Panel for logged in clients (using default django auth views)
  • Admin panel (Mezzanine also using default auth views)
Before that change everything worked as I've expected:
  • Users were going to /panel/ and after login they were redirected to /panel/ or /panel/sub-page/ set with LOGIN_REDIRECT_URL
  • Admins were going to /admin/ and after login they were redirected to /admin/
  • For both cases the direct link to subpages like also worked. After passing login form users were redirected to initial requested page.
Now everything based on Django default login actions redirects to admin. Looks like Mezzanine is also overwriting this stuff

I wanted to dive into it and see if I could make some working commits for it but as someone raised this one before I wanted to throw my 5 cents in now.

Maybe Steve can say something about how to deal with that and what's the intention in those changes? 

...or maybe somethings wrong with my setup :)

2011/2/26 Tom von Schwerdtner <tom...@gmail.com>

I'm guessing this is an issue with the Mezzanine admin login form as the Django admin login will (apparently) normally ignore the LOGIN_REDIRECT_URL setting as it is intended for user-based login and not admin-based login.



--
Pozdrawiam,
Michał

Stephen McDonald

unread,
Feb 27, 2011, 1:12:00 AM2/27/11
to mezzani...@googlegroups.com
Well the idea behind the commit that you linked to was to provide a better default value for LOGIN_URL - Django defaults it to /accounts/login/ which doesn't exist. I changed it to /admin/ so at the very least, it could be used to login with. My understanding was that whichever decorated view was requested prior to being redirected to the login page, would be redirected back to on successful login.

The way I implemented it using "setdefault" should mean that if you define your own value for LOGIN_URL then it is used. If I've missed something please let me know and we'll get it working.

Cheers,
Steve

2011/2/27 Michał Oleniec <mole...@gmail.com>



--
Stephen McDonald

Michał Oleniec

unread,
Feb 27, 2011, 2:20:39 PM2/27/11
to mezzani...@googlegroups.com
Thanks for quick response.

I've made a research and I think that grappelli_safe is missing {{ next }} parameter in login form like in that [1] django -grappelli changeset. It's a fix for Issue 338 [2] in django-grappelli tracker.

So I gave it a try and added the "{{ next }}" field as in the mentioned changeset to my grappelli_safe installation. I'm testing now and everything seems to works like a charm.
I've also removed the s.setdefault for LOGIN_URL setting [3] bacause I think it's unnecessary in that setup. "Next" field in login form take care of all necessary redirects and my "panel" app using django login can live together with Mezzanine admin login in peace.

So to sum this up I think that 2 changes are needed to make Mezzanine play nice with third party apps based on django login functionality.
  1. Add {{ next }} field to login.html in grappelli_safe
  2. Don't need but could remove s.setdefault for LOGIN_URL to make it clear to anybody.
Looking forward for review of that fix.

--
Pozdrawiam,
Michał

Stephen McDonald

unread,
Mar 1, 2011, 2:52:53 AM3/1/11
to mezzani...@googlegroups.com, Michał Oleniec
I've made a slightly different change that should cover this off - Mezzanine has some middleware installed that redirects to the website after logging in if the "site" option is selected. I've modified this so that if a "next" parameter is provided, it will always be redirected to. Incidentally I tried the grappelli fix and it didn't achieve this result.

https://github.com/stephenmcd/mezzanine/commit/e97d67fa70c409c77a3a6e512ba7c0bdfb91b44e

The other change referenced where LOGIN_URL was being set inside Mezzanine was probably a bad idea, and I've changed that now so that the default I wanted to provide for this (/admin/, being a valid URL as opposed to Django's default) is now defined in the project's settings module so it's easily configurable.


Cheers,
Steve

2011/2/28 Michał Oleniec <mole...@gmail.com>
Reply all
Reply to author
Forward
0 new messages