I have previously been using path("", include(wagtail_urls)) for my home_page url which displays the template at home/home_page.html correctly
I wish to however display different pages depending on whether a user is logged in or not so have changed this to:
def logged_in_switch_view(logged_in_view, logged_out_view):
'''switches views dependedn on logon status'''
def inner_view(request, *args, **kwargs):
if request.user.is_authenticated:
return logged_in_view(request, *args, **kwargs)
return logged_out_view(request, *args, **kwargs)
return inner_view
urlpatterns = [
path("",
logged_in_switch_view(
TemplateView.as_view(template_name="home/home_page.html")),
TemplateView.as_view(template_name="home/not_authenticated.html")),
name="home"),
]
With this approach (directly specifying the template rather than using wagtail_urls) the home page does not display correctly when logged in, in that all the wagtail tags in the html e.g. the blog posts are not displaying
home_page.html
{% extends "base.html" %}
{% load wagtailcore_tags wagtailimages_tags %}
{% block content %}
<main class="container">
{% for post in page.blogs %}
{% with post=post.specific %}
<div class="col-md-8 mx-auto px-auto">
<div class="row border rounded overflow-auto flex-md-row mb-4 shadow-sm position-relative ">
<div class="col p-4 d-flex flex-column position-static">
<strong class="d-inline-block mb-2 text-primary">{{ post.category }}</strong>
<div class="mb-1 text-muted">{{ post.date }}</div>
<h3 class="mb-0">{{ post.title }}</h3>
<p>{{post.intro}}</p>
</div>
<div class="col-auto my-auto py-2 px-2 d-none d-lg-block">
<a href="{% pageurl post %}" class="stretched-link">
{% with post.main_image as main_image %}{% if main_image %}
{% image main_image min-250x250 max-350x350%}
{% endif %}{% endwith %}
</a>
</div>
</div>
</div>
{% endwith %}
{% endfor %}
</main>
{% endblock %}
How should I specify the home_page in the logged_in_switch_view function?