I have been thinking, is possible to have a view and have sub views off it, so that more than one view can be displayed on a single web page ?
What I am trying to do, is to have a Django reference section similar to what W3Schools Django References has.
I have Links to different reference sections (eg Template Tags Reference, Filter Reference etc) on my main home page, as can be seen below.
This post does not allow me to show another screenshot, but when Template Tag Ref Page Link is clicked, it is meant to display results of all template tags on a /template/ route.
At the moment to keep it working I have shown autoescape off and this is what gets displayed on localhost template/ route below.
I have not been able to get autoescape on displayed below this example, because it has same view.
Django Template Tag Reference
autoescape Template Tag
Autoescape Off
Hello my World!
Check out views.py to see what the heading variable looks like
I have paths setup in urls.py, like this
# Add Routes for Django References Section
# Template Tag Reference
path('template/', views.template, name='template'),
# Filter Reference
path('filter/', views.filter, name='filter'),
# Field Lookups Reference
path('field/', views.field, name='field'),
This a Template Page view I have setup in my views.py
# Django References Section (57 to 59)
# Django Template Tag Reference 57 within Django References Section
# Using Keyword Autoescape
# Autoescape Off
#def template_autoescape_off(request):
def template(request):
template = loader.get_template('template_tag_ref.html')
context = {
'heading': 'Hello <i>my</i> World!',
}
return HttpResponse(template.render(context, request))
Note: I was trying to use def template_autoescape_off(request): as a sub view, but because that did not work, I have commented it out.
I have also commented out template view for autoescape on as shown in code below, because it did not work with same template view.
# Autoescape On
#def template(request):
#template = loader.get_template('template_tag_ref.html')
#context = {
#'heading': 'Hello <i>my</i> World!',
#}
#return HttpResponse(template.render(context, request))
I thought that having all tag references displayed on one page, even though it is long, would cut down on having heaps of routes.
I am also thinking on my localhost home page, if you click on Template Tag Reference and it takes you to localhost /template/ route, all Links could be displayed for each of the tags.
This would be similar to what W3Schools has, but a lot of routes would be needed like /ref_tags_autoescape/ etc and some of these references have more than one example, so they would need more than one view in the page.
I am trying to get some advice on the best way to approach this, so that it works efficiently for me, thanks.