1👍
You’re passing attributes that do not have any value as your defaults. You should do this instead:
from datetime import datetime as dt
def get(self, request, year=None, month=None):
if year is None:
year = dt.today().year
if month is None:
month = dt.today().month
To use this in your template:
<li><a href="{% url 'entry0' %}">Entry</a></li>
0👍
Your url template tag should get keyword args instead of just args
<li><a href="{% url 'entry' year=year month=month%}">Entry</a></li>
0👍
OK, first things first. The whole logic of yours isn’t clean or pythonic.
You need 1 url, 1 view and 1 template
url(r'^entry/(?P<year>\d{4})/(?P<month>\d{1,2})/$', Entry.as_view(),name='entry')
define your view
def get(self, request, year=None, month=None):
Now, inside your view check if your params have value None,
if (year is None) and (month is None) :
# set today values
mplah mplah mplah…..
hope you get the point….
Source:stackexchange.com