How to customize the templates and create custom views
Hi i have a problem, i need to customize a view by passing something specific on the context, but the problem that i have is that if i recall my custom templates inside the default _templates/pages folder they are not recognized as templates (?)
but if i copy the template inside a local "templates" folder inside my app, it say: 'TemplateSyntaxError at /school
Invalid template name in 'extends' tag: ''. Got this from the 'layout' variable. '
How can i resolve this issue? I also tryed copying all the content of _templates folder inside my "templates" folder but it gives the same error.
Replies (1)
if you want to customize the layout in your views.py file using the KTTheme class, you can add the following code:
def your_view(request):
# Your view logic here
# Update the context to set the custom layout
context.update({
"layout": KTTheme.setLayout("default.html", context),
})
# Return the rendered template with the updated context
return render(request, "your_template.html", context) Here's what this code does:
Import the KTTheme class from your themes module. Replace 'your_app_name' with the actual name of your app.
In your view function (your_view in this example), add the logic for your view.
Update the context dictionary with the layout using KTTheme.setLayout('default.html', context). This sets the layout for your template to 'default.html'. You can replace 'default.html' with the name of the layout you want to use.
Finally, render your template ('your_template.html' in this example) with the updated context.