'How do I use start-app template context in a template file?
I have the current setup for a Django app template which I pass to start-app like so:
python3 manage.py start-app --template template/ myapp
With a directory structure like this:
template/
templates/app_name/
page.html
...
app.py
app.py uses the template context passed when start-app is run, and works fine!
# app.py
from django.apps import AppConfig
class {{ camel_case_app_name }}Config(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = '{{ app_name }}'
However, I'm trying to get similar behaviour out of page.html, to no avail.
{% extends "{{ app_name }}/otherpage.html" %}
{% block content %}
<p>Hello from {{ camel_case_app_name }}!</p>
{% endblock %}
If I run start-app like normal, the template is copied over and the app name is not inserted. If I try to run start-app with --extension py,html I don't get the expected behaviour either, because the template is rendered.
Is there a way to convert the {{ app_name }} calls in page.html without attempting to render the entire template?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
