how to let django return response to web browser at my own function

19 views
Skip to first unread message

肖子聪

unread,
Feb 6, 2019, 6:54:46 AM2/6/19
to Django users
I want to write a function 'get_user_or_log_in' to check whether the user has logged or not. If logged, return user's name, if not, redirect to the login page. I want to use it like function 'get_object_or_404'. But I do not know how to let django response at my own function not just at the end of functions in views.py .

Matthew Pava

unread,
Feb 6, 2019, 9:02:06 AM2/6/19
to django...@googlegroups.com
You probably just want to use the login_required decorator.
https://docs.djangoproject.com/en/2.1/topics/auth/default/#the-login-required-decorator
--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1c4981ef-a3bc-40c3-a521-0287442f37b9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages