我正在尝试将一些变量传递给我在django中的视图。所需信息是用户是否需要下个月或上个月以及当前月份。这是我到目前为止所得到的......
<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>
我已经有了下一个和之前的工作 - 没问题!但我无法得到年月信息。观点:
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 }}"
...... 由于
答案 0 :(得分:1)
您需要使用&
来分隔GET参数。
<a href="{% url 'tande:holiday' %}?value=previous&year={{ year }}&month={{ month }}"
我不明白你的第二个问题。