Python Django 1.6:&x27;instancemethod';对象没有属性'__获取项目';
我的模板中有一个下拉菜单,我试图存储用户为过滤医生对象所做的选择。但我一直在犯这样的错误:Python Django 1.6:&x27;instancemethod';对象没有属性'__获取项目';,python,django,templates,session,Python,Django,Templates,Session,我的模板中有一个下拉菜单,我试图存储用户为过滤医生对象所做的选择。但我一直在犯这样的错误: Traceback: File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response 114. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/L
Traceback:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/django/views/decorators/csrf.py" in wrapped_view
57. return view_func(*args, **kwargs)
File "views.py" in doclistings
91. if request.session.get["selection"] == "Dentist":
Exception Type: TypeError at /doclistings/
Exception Value: 'instancemethod' object has no attribute '__getitem__'
这是索引模板
<div class="signup">
<div class="form-group">
<form action="/doclistings/" method="get" >
<select class="form-control" id="selection" name="selection">
<option><b>Find a Doctor...</b></option>
{% for value, text in form.selection.field.choices %}
<option value="{{ value }}">{{ text }}</option>
{% endfor %}
{% csrf_token %}
</select>
医生模型具有专业化属性,我正试图根据用户选择筛选医生 是一种方法
request.session.get('selection')
是一种方法
request.session.get('selection')
谢谢。。它消除了错误,但没有根据选择过滤医生。你知道这背后的原因吗?谢谢。。它消除了错误,但没有根据选择过滤医生。你知道这背后的原因吗?
def doclistings(request):
d = getVariables(request)
doctors = Doctor.objects.all().order_by('-likes')
paginator = Paginator(doctors, 20) #Show 20 doctors per page
page = page = request.GET.get('page')
# print request.session["selection"]
# print request.session.get("selection", None)
if request.session.get["selection"] == "Dentist":
doctors = Doctor.objects.filter(specialization = "Dentist").order_by('-likes')
try:
doctors = paginator.page(page)
except PageNotAnInteger:
doctors = paginator.page(1)
except EmptyPage:
doctors = paginator.page(paginator.num_pages)
d['doctors'] = doctors
d['paginator'] = paginator
return render_to_response('meddy1/doclistings.html',d)