1👍
✅
The problem is that you are not using a RequestContext in the sub-template – and you won’t be able to, because you would need to pass the request into the get_rendered_html
method, but you can’t pass parameters into methods from the template.
You should rewrite this as a custom inclusion tag which can automatically take the context and render the template:
@register.inclusion_tag('explore_photo.html', takes_context=True)
def explore(context, obj):
return {'user': context['user'], 'object': obj.content_object}
and call it in the template:
{% load my_template_tags %}
...
{% for photo in photos %}
{% explore photo %}
<hr>
{% endfor %}
0👍
You need to add 'django.core.context_processors.request',
in your settings.py
example
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.core.context_processors.tz',
'django.contrib.messages.context_processors.messages',
'django.core.context_processors.request',
)
- [Answer]-Running submit() twice to submit to different forms at once
- [Answer]-Django deployment final step
- [Answer]-Django bootstrap toolkit not responsive. How to force it to be?
- [Answer]-Django rest framework serialization error
Source:stackexchange.com