[Answered ]-Check for a specific url and render jinja2 / html

1👍

Since you want to scale this later, don’t do this in the template. Put the logic into a view function, then pass a variable to the render function that stores the name of the template you want to include. E.g.:

def the_view(request):
    if request.path == '/siteID/abcde/':
        template = 'file1.html'
    elif request.path == '/siteID/fgh/':
        template = 'file2.html'
    else:
        template = 'file_default.html'
        
    return render(request, 'base.html', {'template_to_include': template})

Then in your base.html template put this dynamic import line somewhere:

{% include template_to_include %}
👤Dauros

Leave a comment