2011-10-18 32 views
0

我有這樣的: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'在url.Now在我看來我想檢查哪個(顯示/下載)已被選中。現在它看起來像這樣:

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) 

顯然,這樣的名字= request.GET.get(「LTSP ' '')' 是錯誤的獲取。如何從該表單下載或顯示。我已經嘗試過'name = request.GET.get('name')'和name = request.GET.get('value')。 任何幫助表示讚賞!

回答

1

嘗試給select的名稱和使用越來越所選值時:

name = request.GET['name-of-select'] 
+0

非常感謝你現在的作品! –