I'm trying to write a context processor that will pass a variable year to the template, the value of which will be the current year as a number: © {{ year }} Copyright
from datetime import datetime, date
def year(request):
return {
request, datetime.now().date()
}
CodePudding user response:
You need to return a dictionary, not a set. That dictionary should contain as key the name of the variable, and as value the value you want to associate with that, so here this will look like:
from django.utils.timezone import now
def year(request):
return {
'year': now().year
}
CodePudding user response:
You can use the Built-in "now" templatetag https://docs.djangoproject.com/en/3.2/ref/templates/builtins/#now
© {% now "Y" %} Copyright