Discussion:
login_required decorator in Django: open modal instead of redirecting to another page
Roh Codeur
2015-04-08 19:25:18 UTC
Permalink
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?
--
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.
Avraham Serour
2015-04-09 10:07:47 UTC
Permalink
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
Post by Roh Codeur
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
http://www.fashiolista.com/). To achieve this, I thought I could setup a
middleware(instead of using login_required) and return a response like
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.
http://onecreativeblog.com/post/59051248/django-login-required-middleware
Any ideas?
--
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
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
<https://groups.google.com/d/msgid/django-users/1fa57021-7f12-466e-902f-52fd6b4e78c4%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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/CAFWa6t%2BFk3n%2BRqdmqphC5Q8EQ0yEq2QXPd2ZpHfeYT4c7qMXQA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Luis Zárate
2015-04-10 03:20:28 UTC
Permalink
You need ajax,

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

https://github.com/yceruto/django-ajax
Post by Avraham Serour
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
Post by Avraham Serour
and also use the regular login required decorator because some people
turn off js
Post by Avraham Serour
Post by Roh Codeur
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.
Post by Avraham Serour
Post by Roh Codeur
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
Post by Avraham Serour
Post by Roh Codeur
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.
Post by Avraham Serour
Post by Roh Codeur
I am using Bootstrap for showing modal dialogs.
http://onecreativeblog.com/post/59051248/django-login-required-middleware
Post by Avraham Serour
Post by Roh Codeur
Any ideas?
--
You received this message because you are subscribed to the Google
Groups "Django users" group.
Post by Avraham Serour
Post by Roh Codeur
To unsubscribe from this group and stop receiving emails from it, send
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
.
Post by Avraham Serour
Post by Roh Codeur
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
Post by Avraham Serour
To unsubscribe from this group and stop receiving emails from it, send an
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/CAFWa6t%2BFk3n%2BRqdmqphC5Q8EQ0yEq2QXPd2ZpHfeYT4c7qMXQA%40mail.gmail.com
.
Post by Avraham Serour
For more options, visit https://groups.google.com/d/optout.
--
"La utopía sirve para caminar" Fernando Birri
--
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/CAG%2B5VyP9ZFJdhyi0y__Hk4wuVAfDfpUHFf4sGd8FgPwtgTpPkQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Roh Codeur
2015-04-13 22:33:57 UTC
Permalink
I ended up going with Avraham's response in this.
Post by Roh Codeur
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
http://www.fashiolista.com/). To achieve this, I thought I could setup a
middleware(instead of using login_required) and return a response like
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.
http://onecreativeblog.com/post/59051248/django-login-required-middleware
Any ideas?
--
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/5c3278b0-4688-4784-8a1f-7b037a6d1519%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Avraham Serour
2015-04-14 06:26:58 UTC
Permalink
good to know I'm being useful! :) thanks
Post by Roh Codeur
I ended up going with Avraham's response in this.
Post by Roh Codeur
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
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?
--
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
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/5c3278b0-4688-4784-8a1f-7b037a6d1519%40googlegroups.com
<https://groups.google.com/d/msgid/django-users/5c3278b0-4688-4784-8a1f-7b037a6d1519%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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/CAFWa6tJ_r%2Bf3wLfQQ43%2BEG8z1SN%3D_XWun2akAj1QbpT72xH6kA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...