How to specify the login_required redirect url in django?

后端 未结 7 1276
既然无缘
既然无缘 2020-12-13 23:04

I have a view function:

@login_required
def myview():
    # do something
    # respond something
    pass

How can I specify the exact URL f

7条回答
  •  难免孤独
    2020-12-13 23:36

    In django project settings

    add below code

    LOGIN_REDIRECT_URL = 'path/to/url'
    

    and then import this LOGIN_REDIRECT_URL in your views and add

    `@login_required(login_url=LOGIN_REDIRECT_URL)`
    

    to the top of your views you want to restrict it will work

提交回复
热议问题