[Answered ]-Redefining home in django

0👍

This is generally how I would go about it. You can add context if needed.

views.py:

from django.shortcuts import render

def home(request):
    if request.user.is_authenticated():
        return user_home(request)
    else:
        return login_home(request)

def user_home(request)
    return render(request, 'path/to/user_template.html')

def login_home(request)
    return render(request, 'path/to/login_template.html')

1👍

You need simple check in view:

if request.user.is_authenticated():
    return HttpResponseRedirect('/profileurl/')
👤ndpu

1👍

An easy way to do it would be a redirect to another view:

MyApp.views

def home(request):
  if request.user.is_authenticated():
    redirect
  else:
    home page

If you want the actual url entry to load a different template than the home page, or a modified home page, you could just as easily render whatever template you wanted in response to the url request instead of issuing a redirect

Leave a comment