我需要通过某些date
查询模型。日期通过网址传递给reservation_f
。但是给我这个错误:
[u'\u0645\u0642\u062f\u0627\u0631 \u062a\u0627\u0631\u06cc\u062e \xab2016\xbb \u062f\u0631 \u0642\u0627\u0644\u0628 \u0646\u0627\u062f\u0631\u0633\u062a\u06cc \u0648\u0627\u0631\u062f \u0634\u062f\u0647 \u0627\u0633\u062a. \u0628\u0627\u06cc\u062f \u062f\u0631 \u0642\u0627\u0644\u0628 YYYY-MM-DD \u0628\u0627\u0634\u062f.']
models.py:
class Food(models.Model):
serve_date = models.DateTimeField(verbose_name="Serve Date", auto_now_add=False)
views.py:
def reservation_f(request, year, month, day):
food = Food.objects.filter(serve_date__year = year, serve_date__month = month, serve_date__day = day)
return render(request, 'food.html', {'food':food})
urls.py:
urlpatterns = [
url(r'^reserve/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<day>[0-9]{2})/$', reservation_views.reservation_f, name='reserve')
]
template.html:
<a href="{% url 'reserve' date.serve_date|date:"Y/m/d" %}">
{{date.serve_date }}
</a>