Django, redirect all non-authenticated users to landing page

前端 未结 8 1377
挽巷
挽巷 2021-01-30 23:08

I have a django website with many urls and views. Now I have asked to redirect all non-authenticated users to a certain landing page. So, all views must check if user.is_a

8条回答
  •  盖世英雄少女心
    2021-01-30 23:57

    You can avoid specifying login_url by setting LOGIN_URL.

    In settings.py:

    LOGIN_URL = ''
    

    In views.py:

    @login_required
    def some_view_function(request):
    

    If you need redirect within a view function, you can do so with:

    return redirect_to_login(request.get_full_path())
    

提交回复
热议问题