SyntaxError: keyword can't be an expression (views.py)
SyntaxError: keyword can't be an expression (views.py)
我的views.py:
def filter(request, param):
att = Attendancename.objects.filter(date.hours=int(param))
return render(request, 'listatten.html', {'attendance': att})
我的urls.py:
url(r'^filter/(?P<param>\d+)$', views.filter, name = 'filter'),
我的模板:
<html>
<head><title> Attendance </title></head>
<center><h1>My Attendance</h1></center>
<select name='select_month'>
<option value="00">---</option>
<option value="<a href="{% url 'student:filter' param=1 %}"></a>>">Jan</option>
<option value="<a href="{% url 'student:filter' param=2 %}"></a>>">Feb</option>
<option value="<a href="{% url 'student:filter' param=3 %}"></a>>">Mar</option>
<option value="<a href="{% url 'student:filter' param=4 %}"></a>>">Apr</option>
<option value="<a href="{% url 'student:filter' param=5 %}"></a>>">May</option>
<option value="<a href="{% url 'student:filter' param=6 %}"></a>>">Jun</option>
<option value="<a href="{% url 'student:filter' param=7 %}"></a>>">Jul</option>
<option value="<a href="{% url 'student:filter' param=8 %}"></a>>">Aug</option>
<option value="<a href="{% url 'student:filter' param=9 %}"></a>>">Sept</option>
<option value="<a href="{% url 'student:filter' param=10 %}"></a>>">Oct</option>
<option value="<a href="{% url 'student:filter' param=11 %}"></a>>">Nov</option>
<option value="<a href="{% url 'student:filter' param=12 %}"></a>>">Dec</option>
</select>
</html>
以上是我的views.py和模板文件。我想在我的 html 模板文件中下拉月份,以便在 select 特定月份时根据月份过滤我的列表,所以我在 '<select option="<--->">'
中给出了 url ] 带有一个参数,然后通过 urls.py 语句将其传递给查看。
它引发了上述异常。我认为按我的方式实现是不可能的。
请告诉我如何实现它?
Django 使用双下划线 __
表示法进行这样的查找。您可以使用 hour 查找。
att = Attendancename.objects.filter(date__hours=int(param))
我的views.py:
def filter(request, param):
att = Attendancename.objects.filter(date.hours=int(param))
return render(request, 'listatten.html', {'attendance': att})
我的urls.py:
url(r'^filter/(?P<param>\d+)$', views.filter, name = 'filter'),
我的模板:
<html>
<head><title> Attendance </title></head>
<center><h1>My Attendance</h1></center>
<select name='select_month'>
<option value="00">---</option>
<option value="<a href="{% url 'student:filter' param=1 %}"></a>>">Jan</option>
<option value="<a href="{% url 'student:filter' param=2 %}"></a>>">Feb</option>
<option value="<a href="{% url 'student:filter' param=3 %}"></a>>">Mar</option>
<option value="<a href="{% url 'student:filter' param=4 %}"></a>>">Apr</option>
<option value="<a href="{% url 'student:filter' param=5 %}"></a>>">May</option>
<option value="<a href="{% url 'student:filter' param=6 %}"></a>>">Jun</option>
<option value="<a href="{% url 'student:filter' param=7 %}"></a>>">Jul</option>
<option value="<a href="{% url 'student:filter' param=8 %}"></a>>">Aug</option>
<option value="<a href="{% url 'student:filter' param=9 %}"></a>>">Sept</option>
<option value="<a href="{% url 'student:filter' param=10 %}"></a>>">Oct</option>
<option value="<a href="{% url 'student:filter' param=11 %}"></a>>">Nov</option>
<option value="<a href="{% url 'student:filter' param=12 %}"></a>>">Dec</option>
</select>
</html>
以上是我的views.py和模板文件。我想在我的 html 模板文件中下拉月份,以便在 select 特定月份时根据月份过滤我的列表,所以我在 '<select option="<--->">'
中给出了 url ] 带有一个参数,然后通过 urls.py 语句将其传递给查看。
它引发了上述异常。我认为按我的方式实现是不可能的。
请告诉我如何实现它?
Django 使用双下划线 __
表示法进行这样的查找。您可以使用 hour 查找。
att = Attendancename.objects.filter(date__hours=int(param))