I am have a django project that I am creating. Within the django project I have two apps which as user and common. I want to use a method that validates if a user is logged in from the common apps views.py file within the user views.py file. How can I can the LoggedIn method from the common view.py in a method from he user views.py Home method....
User -> views.py file:
# checks if someone is logged in
def Home(request):
# check if there is a user logged in
currentUser = LoggedIn(request)
# no user logged in
if currentUser == None:
# send user to the main sign in and log in form
return redirect('Signup')
# a user logged in
else:
# users home page content will be down below
parameters = 'parameters'
Common -> views.py file:
def LoggedIn(request):
if 'username' not in request.session:
return None
else:
user = request.session['username']
currentUser = User.objects.get(username=username)
return curentUser
I cant seem to get how to call one method from a different app. I don't want to have to redirect the user but rather just call the method and return a value to the Home method in the user app views.py file. Couldn't find any documentation on this matter.