Hi, my index view should query some data with the default "date of the day"value.
For a test, I entered a string as a default value. : “2019-08-01”
My url :
urlpatterns = [
path('<str:date_index>', views.index, name='index'),
]
My view:
def get_reunions_by_date(date_r):
return Reunion.objects.filter(datetime_start__startswith=date_r) \
.order_by('numero', 'hippodrome__nom')
def index(request, date_index="2019-08-01"):
year, month, day = map(int, date_index.split('-'))
date_du_jour = date(year, month, day)
return render(request, 'myapp/index.html', {
'reunions': get_reunions_by_date(date_du_jour),
'date_du_jour': date_du_jour
})
Now, If I enter this url : myapp/2019-01-01
, it’s working, the index template is rendered, but if I enter this url: myapp/
nothing is rendered.
Why is it not takking the default value date_index="2019-08-01"
in the view ?
I don’t understand.