Is it possible to make 302 for architecture in my web application?

For example, in my index (query):

def index(request):
    if logged_in:
        return HttpResponseRedirect("/home_profile")
    else:
        return HttpResponseRedirect("/login")

That way, when a user clicks on my home page ... he is redirected accordingly. Is this a good architecture? Or will it cause caching problems, etc.?

+3
source share
1 answer

The redirection is fine (302 should not cause caching problems, since 302 are temporary), but why do you need to redirect to both if and another. It is best to redirect to the login page if you are not logged in, otherwise the view should return a response instead of an unnecessary redirect, for example.

def home(request):
    if not  logged_in:
        return HttpResponseRedirect("/login?next=%s"%reverse("home"))

    return HttpResponse(...)

, , , djago auth l ogin_required , .

, URL- , , .

+3

Source: https://habr.com/ru/post/1734664/


All Articles