I have a function in views.py
def get_interview_type(request):
i = None
title = request.GET['title'] #Here the title becomes different
try:
i = Interview.objects.get(title=title) #it looks for that dropdown value
#Error according to pdb
#-> i = Interview.objects.get(title=title)
# (Pdb)
# DoesNotExist: DoesNotE...exist.',)
if i.interview_type == "Time Series":
visit_ids = i.visit_set.all()
reference_visit_list = []
for visit in visit_ids:
reference_visit_list.append(visit.reference_visit)
reference_visit_list.extend(visit_ids)
list(set(reference_visit_list))
len_visits=filter(None,reference_visit_list)
total_visits = len(len_visits)
return render_to_response('export/get_details.html',
{'visits':visit_ids,'count':visit_ids.count(),
'total_visits':total_visits},
context_instance=RequestContext(request)
)
else:
return render_to_response('export/get_interview_type.html',
{'visits':i.visit_set.all()},
context_instance=RequestContext(request)
)
except Interview.DoesNotExist:
pass
When the user selects a title from the dropdown this function is called and does it tasks.
Now i have entered a string which include ‘&’ ampersand thinking that it can play a role of ‘and’ in normal english like this :-
‘CI-2-UGI & Bowel Symptom Screening & Characterization'(It is one of that dropdown value)
Now when user selects this value from dropdown the title does not remain the same, instead the title changes to CI-2-UGI(in title = request.GET[‘title’]) and before the function executes i recieve a 500 error page.
This is what the error prints in runserver mode
/home/user/cpms/careprep/tags/4.0/careprep/export/views.py(66)get_interview_type()->None
-> pass
(Pdb) c
[11/Mar/2012 22:05:20] “GET /export/get_interview_type/?title=CI-2-UGI%20&%20Bowel%20Symptom%20Screening%20&%20Characterization HTTP/1.1” 500 64490
Also when i remove that ‘&’ampersand from the title there is no 500 page.
Why this & causing the problem ? I think in this way every special symbol will cause the same problem .I will appreciate if anybody can guide me on this and how to solve this problem
Because
&is used to separate fields in the query string. URL-encode it first.