我有这个:
<form action='/ltsp' method='GET'>
<label>Download Option:</label>
<select name=''>
<option name='download' value='download'>download</option>
<option name='show' value='show'>show</option>
</select>
<input type='submit' value='Ausführen'>
</form>
在我的模板中。它在url中显示如下'.... de / ltsp?= download'。在我看来,我想检查哪个(显示/下载)已被选中。现在它看起来像这样:
def a(request):
if request.method == 'GET':
a = \
A.objects.all().order_by('hostname').distinct()
b = B.objects.all().order_by('name').distinct()
if request.GET.get('name'):
name = request.GET.get('ltsp', '')
if name is 'download':
response = render_to_response(
'thin/lts.conf', {
'a': a,
'b': b
}, mimetype='text/plain')
response["Content-Disposition"] = "attachment; \
filename=lts.conf"
return response
elif name is 'show':
return render_to_response(
'thin/lts.conf', {
'a': a,
'b': b
}, mimetype='text/plain')
else:
return HttpResponse(content="Failed", \
mimetype="text/plain", status=400)
else:
return HttpResponseBadRequest(content="Failed", mimetype="text/plain", \
status=400)
else:
return HttpResponseBadRequest(content="Failed", mimetype="text/plain", \
status=400)
显然这样做'name = request.GET.get('ltsp','')'是错误的。如何从该表单下载或显示。我已经尝试了'name = request.GET.get('name')'和name = request.GET.get('value')。 感谢任何帮助!
答案 0 :(得分:1)
尝试为select
提供一个名称,并在获取所选值时使用该名称:
name = request.GET['name-of-select']