Django, redirect all non-authenticated users to landing page

前端 未结 8 1388
挽巷
挽巷 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:52

    see the docs for login required decorator

    from django.contrib.auth.decorators import login_required
    
    @login_required
    def my_view(request):
        ...
    

    another option is to add it to your urls.py patterns, see this answer

    urlpatterns = patterns('',
        (r'^foo/$', login_required(direct_to_template), {'template': 'foo_index.html'}),
    )
    

提交回复
热议问题