1π
β
A context processor would be the typical way to do this.
def recent_issues(request):
{'recent_issues': return Issue.objects.order_by('-issue_num')[1:6]}
Once you add the context processor to your TEMPLATES
settings, you can access recent_issues
in the template.
Alternatively, if you donβt want a context processor to run for every view, you can create a template tag using the simple_tag
decorator (in Django < 1.9 use an assignment tag).
@register.simple_tag
def recent_issues():
return Issue.objects.order_by('-issue_num')[1:6]
In your template, use the tag to assign the queryset to a variable
{% recent_issues as recent_issues %}
You can now loop through recent_issues
in the template.
π€Alasdair
0π
Maybe I donβt understand your question very well, but are you looking for something like this:
{% include "some_include_template.html" with some_list=some_list some_var=some_var %}
?
π€dentemm
- Issue with Django URL Mapping/DetailView
- TypeError: %d format: a number is required, not datetime.timedelta
- (django) Why do I get an error when adding app to INSTALLED_APPS but not when just importing?
Source:stackexchange.com