Django Template not loading the view inside another template
I am trying to include another template inside my home page as follows:
{% if user.userorganisation.organisation %}
{% include 'organisation_members.html' %}
{% else %}
{% include 'create_organisation.html' %}
{% endif %}
The create_organisation template is correctly loading its view so the step of checking the organisation of the user is correct. When I am trying to directly access the organisation_members.html url everything is working fine but when I am inside the home page where the include 'organisation_members.html' exists, only the static contents are being loaded.
I have tried adding some prints for debugging and the view is not being called at all. Here is the view:
def organisation_members(request):
print("aaaaaa")
try:
print("aaaaaaaa")
user_organisation = UserOrganisation.objects.get(user=request.user)
print(user_organisation.organisation)
organisation_users = UserOrganisation.objects.filter(
organisation=user_organisation.organisation).select_related('user')
print(organisation_users)
context = {
'organisation_users': organisation_users,
}
return render(request, 'organisation_members.html', context)
except UserOrganisation.DoesNotExist:
return redirect('some_error_page')
And here is the url:
path('organisation_members/', views.organisation_members,name='organisation_members'),
Why is the view not being called when including the html page? I know that the 'include' only includes the html but why is it that the create_organisation.html being called and the organisation_members not, when I am doing the same exact steps in both of them