Reputation: 888
I am trying to pass a few variables to my view in django. The information needed is whether the user wanted the next or previous month, and the current month. Here is what I have got so far...
<a href="{% url 'tande:holiday' %}?value=previous" class='previous' id='previous' name='previous'><<-Previous</a> <a href="{% url 'tande:holiday' %}?value=next" name = 'next' class='next' id='next'>Next->></a>
I've got the next and previous bits to work - no problem! But I can't get the year and month information. The view:
def holiday(request, value=None):
if request.method == "GET":
if value != None:
#THIS IS WHAT I NEED TO GET
current_year = request.GET.get('year')
current_month = request.GET.get('month')
value = request.GET.get('value')
if value == "next":
#calculate next month
year = next_month.year
month = next_month.month
if value == "previous":
#calculate previous month
year = last_month.year
month = last_month.month
else:
date_today = datetime.now()
year = date_today.year
month = date_today.month
#......
# render html calendar with a form for input requesting holiday
context = {
# dont know if i need this...??
"year": year,
"month": month,
}
return render(request, "tande/calendar.html", context)
<a href="{% url 'tande:holiday' %}?value=previous?year={{ year }}?month={{ month }}"
... Thanks
Upvotes: 0
Views: 737
Reputation: 600059
You need to use &
to separate GET parameters.
<a href="{% url 'tande:holiday' %}?value=previous&year={{ year }}&month={{ month }}"
I don't understand your second question.
Upvotes: 1