login_required decorator in Django: open modal instead of redirecting to another page

339 views
Skip to first unread message

Roh Codeur

unread,
Apr 8, 2015, 8:53:35 PM4/8/15
to django...@googlegroups.com

Hi

I have a django app which has certain sections which are reserved for registered users. I have the views annotated with login_required decorator which redirects the user to a login page.

However, I would like to keep the user on the same page and open up a modal dialog prompting user to sign in(like on the website: http://www.fashiolista.com/). To achieve this, I thought I could setup a middleware(instead of using login_required) and return a response like below:

   return HttpResponse("<script>"
       "showLogin()"
       "</script>")

When I try to do this, I realised that this renders a page with only the script tag, which obviously doesnt work.

I am using Bootstrap for showing modal dialogs.

Middleware link: http://onecreativeblog.com/post/59051248/django-login-required-middleware

Any ideas?


Avraham Serour

unread,
Apr 9, 2015, 6:08:42 AM4/9/15
to django...@googlegroups.com
you should return the whole page plus the modal dialog

I would do it in js, the js context should e aware that the session is not logged in and instead of going to the link it should show the modal
and also use the regular login required decorator because some people turn off js

--
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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
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/1fa57021-7f12-466e-902f-52fd6b4e78c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Luis Zárate

unread,
Apr 9, 2015, 11:20:57 PM4/9/15
to django...@googlegroups.com
You need ajax,

l have suggested django-ajax a lot because it is awesome

https://github.com/yceruto/django-ajax
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFWa6t%2BFk3n%2BRqdmqphC5Q8EQ0yEq2QXPd2ZpHfeYT4c7qMXQA%40mail.gmail.com.

> For more options, visit https://groups.google.com/d/optout.
>

--
"La utopía sirve para caminar" Fernando Birri



Roh Codeur

unread,
Apr 13, 2015, 6:33:57 PM4/13/15
to django...@googlegroups.com
I ended up going with Avraham's response in this. 

Avraham Serour

unread,
Apr 14, 2015, 2:27:41 AM4/14/15
to django...@googlegroups.com
good to know I'm being useful! :) thanks

--
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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages