Gaurav Tomer
Gaurav Tomer

Reputation: 731

SyntaxError: keyword can't be an expression (views.py)

my views.py:

def filter(request, param):
    att = Attendancename.objects.filter(date.hours=int(param))
    return render(request, 'listatten.html', {'attendance': att})

my urls.py:

url(r'^filter/(?P<param>\d+)$', views.filter, name = 'filter'),

my template:

<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>

The above is my views.py and template file. I want a drop down of months in my html template file to filter my list as per the month when I select a particular month, So I have given url in the '<select option="<--->">' with a parameter and then pass it to view through urls.py statement as above.

It raise the above exception. I think it's not possible to implement in the way I'm doing.

Please tell me how can I implement it?

Upvotes: 1

Views: 728

Answers (1)

Alasdair
Alasdair

Reputation: 308769

Django uses double underscore __ notation for lookups like this. You can use the hour lookup.

att = Attendancename.objects.filter(date__hours=int(param))

Upvotes: 1

Related Questions