从我的模板:
<a href="{% url 'tracker:othermonth' year next_month %}">July</a>
网址模式:
url(r'^ocal/$', views.calendar, name = "othermonth"),
看法:
def calendar(request, year, month):
my_year = int(year)
my_month = int(month)
my_calendar_from_month = datetime(my_year, my_month, 1)
my_calendar_to_month = datetime(my_year, my_month, monthrange(my_year, my_month)[1])
my_tickets = Event.objects.filter(on_sale__gte=my_calendar_from_month).filter(on_sale__lte=my_calendar_to_month)
my_previous_year = my_year
my_previous_month = my_month - 1
if my_previous_month == 0:
my_previous_year = my_year - 1
my_previous_month = 12
my_next_year = my_year
my_next_month = my_month + 1
if my_next_month == 13:
my_next_year = my_year + 1
my_next_month = 1
my_year_after_this = my_year + 1
my_year_before_this = my_year - 1
cal = TicketCalendar(my_tickets).formatmonth(year, month)
return render_to_response('calendar.html', {'events_list': my_tickets,
'calendar': mark_safe(cal),
'month': my_month,
'month_name': named_month(my_month),
'year': my_year,
'previous_month': my_previous_month,
'previous_month_name': named_month(my_previous_month),
'previous_year': my_previous_year,
'next_month': my_next_month,
'next_month_name': named_month(my_next_month),
'next_year': my_next_year,
'year_before_this': my_year_before_this,
'year_after_this': my_year_after_this,
}, context_instance=RequestContext(request))
错误:
Reverse for 'othermonth' with arguments '(2013, 7)' and keyword arguments '{}' not found.
我已经搜索了 stackoverflow 和 django 文档,但我似乎无法弄清楚为什么会出现此NoReverseMatch
错误。我确信这是我的一个非常简单的疏忽,因为我正在查看以前项目中的代码,该代码几乎与此相同并且运行良好。任何帮助将不胜感激,谢谢。
更新:我尝试删除我试图与 URL 一起发送的参数并修复了NoReverseMatch
但是被调用的视图需要这些参数,因此链接失败。