我正在使用我的django应用程序,而且我有一年到网址的问题。我使用CVB作为视图。以下是我的解决方案,但不起作用。
以下是我的观点:
class EventsListView(ListView):
template_name = 'events/production_list.html'
model = Events
def get_context_data(self, **kwargs):
context = super(EventsListView, self).get_context_data(**kwargs)
year_season = Events.objects.filter(is_active=True).last()
context['year'] = year_season
return context
这是我的网址:
url(r'^/events/(?P<year>)$', EventsListView.as_view()),
答案 0 :(得分:0)
您可以将您的网址更改为:
url(r'^/events/(?P<year>\d{4})$', EventsListView.as_view()),
这假设您使用2017年的年份。
这会将/events/2017/
到2017
的网址解析为year
。