我正在尝试过滤DJango查询当月
models.py
class Album_Requests(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, default=1)
request_date = models.DateTimeField(auto_now_add=True)
request_user = models.CharField(default='', blank=True, max_length=100)
...
...
views.py
def current_month(request):
current_month= Album_Requests.objects.filter(request_date__month='07')
return render(request, 'month.html', {'current_month': current_month})
month.html
{% if current_month%}
{% for album in current_month%}
<tr>
<td>{{album.request_date|date:"Y-m-d H:i " }}</td>
<td>{{albums.current_month}}</td>
</tr>
{% endfor %}
{% else %}
{% endif %}
但是当我尝试打开模板时,出现此错误:
Variable Value
current_month
Error in formatting: OperationalError: function raised exception
datetime
<class 'datetime'>
7
request
<WSGIRequest: GET '/month/'>
有人可以在这里帮助我吗?我不知道该怎么办才能解决此错误。