Hi i need to check the 10th of each month in my django template file , can anybody tell me how can i check this accentually i need to show some data before the 10th of each mont
A few things to understand:
So, in my opinion, the easiest way to do this would be to:
So, our view would look something like:
def sample_view(request, *args, **kwargs):
from datetime import date
current_date = date.today()
current_day = int(current_date.day) # force a cast to an int, just to be explicit
return render_to_response("template", {'day_of_the_month': current_day })
And in our template we would do:
{% if day_of_the_month > 10 %}
{% else %}
{% endif %}
This does expose stuff to your template you might be hiding based on the date for security reasons. You should never hide secure things in a template based on an if/then check.
If you need to do additional checks, you could just pass in current_date
, and check current_date.day
against the number 10 instead of specifically passing in that day. It'd be less explicit, but more generic and flexible.