Reputation: 1990
I have a simple tag from which I return rendered_payload
which has two properties html
and reduxState
:
@register.simple_tag
def header_and_sidebar():
user = {}
# Here's what we've got so far
render_assets = {
'url': '/policy-portal/list',#request.path_info,
'user': user
}
try:
res = requests.post('http://docker.for.mac.localhost:8000/' + 'render', #settings.FRONTEND_URL
json=render_assets,
headers={'content_type': 'application/json'})
rendered_payload = res.json()
except Exception as e:
print(e)
...
return rendered_payload
when I attempt to use the tag in a template as so:
{% load project_tags %}
{% header_and_sidebar.html %}
this errors out with:
Invalid block tag on line 164: 'header_and_sidebar.html'. Did you forget to register or load this tag?
How should I go about accessing a nested property? This setup works fine when I am not trying to access a nested property, so I know it is configured properly for the most part.
Here is my settings.py for good measure:
TEMPLATES = [
{
...
'OPTIONS': {
'libraries': {
'project_tags': 'base.templatetags.custom_tags',
},
...
}
Upvotes: 1
Views: 265
Reputation: 476554
You can store the outcome of the template tag in a variable and then access it:
{% header_and_sidebar as data %}{{ data.html }}
Upvotes: 1