393👍
✅
The full tag to print just the current year is {% now "Y" %}
. Note that the Y must be in quotes.
- [Django]-Embed YouTube video – Refused to display in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'
- [Django]-Django-allauth social account connect to existing account on login
- [Django]-How to pass django rest framework response to html?
- [Django]-Using Cloudfront with Django S3Boto
- [Django]-Django development server reload takes too long
- [Django]-How can I list urlpatterns (endpoints) on Django?
14👍
I have used the following in my Django based website
{% now 'Y' %}
You can visit & see it in the footer part where I have displayed the current year using the below code(CSS part is omitted so use your own).
<footer class="container-fluid" id="footer">
<center>
<p>
©
{% now 'Y' %},
PMT Boys hostel <br>
All rights reserved
</p>
</center>
</footer>
And it is displaying the following centred text in my website’s footer.
©2018, PMT Boys hostel
All rights reserved
- [Django]-Django, Models & Forms: replace "This field is required" message
- [Django]-How to combine django "prefetch_related" and "values" methods?
- [Django]-Reload django object from database
0👍
In my template, aside from the current year, I needed a credit card expiration year dropdown with 20 values (starting with the current year). The select
values needed to be 2 digits and the display strings 4 digits. To avoid complex template code, I wrote this simple template tag:
@register.filter
def add_current_year(int_value, digits=4):
if digits == 2:
return '%02d' % (int_value + datetime.datetime.now().year - 2000)
return '%d' % (int_value + datetime.datetime.now().year)
And used it in the following manner:
<select name="card_exp_year">
{% for i in 'iiiiiiiiiiiiiiiiiiii' %}
<option value="{{ forloop.counter0|add_current_year:2 }}">{{ forloop.counter0|add_current_year:4 }}</option>
{% endfor %}
</select>
- [Django]-*_set attributes on Django Models
- [Django]-Is it bad to have my virtualenv directory inside my git repository?
- [Django]-Convert Django Model object to dict with all of the fields intact
Source:stackexchange.com