Django 表单和 GET 参数
我有这个:
<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>
在我的模板中。它在网址中显示为“....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') 。 感谢任何帮助!
I have this:
<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>
in my template. and it shows up like this '....de/ltsp?=download' in the url.Now in my view i want to check which (show/download) has been chosen. For now it looks like this:
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)
Obviously doing this 'name = request.GET.get('ltsp', '')' is the wrong get. How do I get download or show from that form. I tried 'name = request.GET.get('name')' and name = request.GET.get('value') already. Any help is appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试为
select
指定一个名称,并在获取所选值时使用该名称:Try giving the
select
a name and using that when getting the selected value: