0π
β
It is not possible to include one tag inside another like this.
You can create an assignment tag, which stores the tagβs result in a context variable instead of outputting it.
The example assignment tag in the docs is for a template tag get_current_time
, which you could use instead of the {% now %}
tag.
In your mytags.py
template tag module:
from django import template
register = template.Library()
@register.assignment_tag
def get_current_time(format_string):
return datetime.datetime.now().strftime(format_string)
In your template:
{% load mytags %}
{% get_current_time "%Y" as year %}
<li><a href="{% url 'blog_archive' year=year %}">Archive</a></li>
π€Alasdair
1π
May be better decision is would be set default parameter at the urls.py
?
Example urls.py
:
from django.utils.timezone import now ... urlpatterns = patterns('app.views', url(r'^.../$', 'blog_archive', {'year': now().strftime('%Y')}), )
- [Answer]-Test Django app using models from a second app
- [Answer]-Dynamically populate template from two lists
- [Answer]-Link to register with google gives error from my page but not from allauth page
0π
That is what you want.
Maybe this:
<li><a href="{% url 'blog_archive' year=value|date:"Y" %}">Archive</a></li>
# just pass the datetime object as 'value'
π€Leandro
- [Answer]-Acces html form fields inside django view with request objects
- [Answer]-Use HttpResponse with JSON data in this code
- [Answer]-Switched to django now tab label width is stretching to tab content width⦠Hard to explain
- [Answer]-Regex URL in django doesnt work
Source:stackexchange.com