0👍
Thanks to @tsurantino I was able to get this working using the messages framework. I always like when I have to implement a new feature using a part of Django I haven’t used before. Adding to the toolkit, so to speak. Here is what I did:
Since I had a signal_connectors.py
file already for sending email based on user registration/activation I just added to it:
@receiver(user_logged_out)
def user_logged_out_message(sender, request, **kwargs):
messages.add_message(
request,
messages.INFO,
'You\'ve been successfully logged out. You can log in again below.'
)
Then in my common
app’s __init__.py
I imported it:
from common.signal_connectors import user_logged_out_message
Then in my login.html
template:
{% if messages %}
<div class="alert-success align-ctr font-16px top-mar-2em">
{% for message in messages %}
{{ message }}
{% endfor %}
</div>
{% endif %}
Finally, to redirect to login page after logout (urls.py
):
url(r'^accounts/logout/$','django.contrib.auth.views.logout_then_login'),
Thanks for everyone’s help and comments.
1👍
You should be able to add the following to your urls.py
and have everything work.
url(r'^accounts/logout/$','django.contrib.auth.views.logout_then_login')
Make sure you have LOGIN_URL
defined your settings.py
. Then when a user clicks a logout link they will hit the logout view which takes care of redirecting to the login view which contains your form.
- [Answer]-Django tutorial 1.7 ForeignKey
- [Answer]-How to set 'next' parameter via extra_context in Django
- [Answer]-Django infinite loop to access models
- [Answer]-Use an git repo from an existing app with a new app in openshift
- [Answer]-South not working with Custom Field