Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you reference radiobuttons in views.py using Django or am I way off?
    primarykey
    data
    text
    <p>I am trying to have a search feature for a database. The three different options or chemicals gases and supplies.</p> <pre><code> &lt;form action="/search/" method="get"&gt; &lt;input name="q" type="text"&gt; &lt;input value="Search" type="submit"&gt; &lt;input value="Chemicals" form="radiobuttons" name="item" type="radio"&gt;Chemicals&amp;nbsp; &lt;input value="Gases" form="radiobuttons" name="item" type="radio"&gt;Gases&amp;nbsp; &lt;input value="Supplies" form="radiobuttons" name="item" type="radio"&gt;Supplies &lt;/form&gt; </code></pre> <p>this is the html that I am using. The search feature works like it should but I must be referencing the radio buttons wrong in my view which is posted below.</p> <pre><code>def search(request): error = False item = request.GET['item'] if 'item' in request.GET and request.GET['item']: item = request.GET['item'] if not item: error = True if 'q' in request.GET and request.GET['q']: q = request.GET['q'] if not q: error = True elif len(q) &gt; 20: error = True else: if item == 'Chemicals': chemicals = Chemicals.objects.filter(Name__icontains=q) records = ChemicalRecord.objects.all() recordform = ChemicalRecordForm return render_to_response('search_results.html',locals(), context_instance=RequestContext(request)) return render_to_response('search_form.html',{'error':True}) </code></pre> <p>Thanks, for any tips, advice, insights, or answers.</p> <pre><code>class RadioSelection(forms.Form): CHOICES = ( ('Chemicals','Chemicals'), ('Gasses','Gasses'), ('Supplies','Supplies'), ) Button = forms.RadioSelect(choices=CHOICES) </code></pre> <p>and in the html I try and call it using {{form.Button}} which is what another user had posted on another question that was regarding radibuttons. Nothing show up and it validates correclty (so it says) so I'm not sure if the html is wrong or if the form is built incorrectly thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload