在选择标记html中将表单选择添加为选项

时间:2018-10-10 15:26:34

标签: html django

我正在完成我的最后一个项目,我对现在的工作有些迷茫。 我正在开发一个网站,我需要在html选择标签中插入一些选择,我的意思是,选择必须是该选择标签的选项。我正在尝试,但是下拉菜单未按预期显示,并且当我尝试提交表单时,它给了我一个错误。希望您能帮助我,我快疯了。在这里,我留下了代码,随时问您想要的什么

forms.py

class FormCancion(forms.ModelForm):

    NOTAS_CHOICES=(('35','Acoustic Bass Drum'),('36','Bass Drum 1'),('37','Side Stick'),('38','Acoustic Snare'),('39','Hand Clap'),
    ('40','Electric Snare'),('41','Low Floor Tom'),('42','Closed Hi Hat'),('43','High Floor Tom'),('44','Pedal Hi-Hat'),
    ('45','Low Tom'),('46','Open Hi-Hat'),('47','Low-Mid Tom'),('48','Hi-Mid Tom'),('49','Crash Cymbal 1'),('50','High Tom'),
    ('51','Ride Cymbal 1'),('52','Chinese Cymbal'),('53','Ride Bell'),('54','Tambourine'),('55','Splash Cymbal'),
    ('56','Cowbell'),('57','Crash Cymbal 2'),('58','Vibraslap'),('59','Ride Cymbal 2'),('60','Hi Bongo'),('61','Low Bongo'),
    ('62','Mute Hi Conga'),('63','Open Hi Conga'),('64','Low Conga'),('65','High Timbale'),('66','Low Timbale'),('67','High Agogo'),
    ('68','Low Agogo'),('69','Cabasa'),('70','Maracas'),('71','Short Whistle'),('72','Long Whistle'),('73','Short Guiro'),
    ('74','Long Guiro'),('75','Claves'),('76','Hi Wood Block'),('77','Low Wood Block'),('78','Mute Cuica'),('79','Open Cuica'),
    ('80','Mute Triangle'),('81','Open Triangle'))

   nota_pad_gris = forms.ChoiceField(choices=NOTAS_CHOICES, widget=forms.Select())

views.py:

def crearCancion(request):

    cancion=Cancion()
    if request.method=="POST":
        formulario=FormCancion(request.POST,request.FILES,instance=cancion)
        if formulario.is_valid():
            formulario.save()
            return HttpResponseRedirect('/ListadoCanciones/')
    else:
        formulario=FormCancion()
        context={'formulario':formulario}
        return render(request,"nuevaCancion.html",context)

.html:

<br><br><br>
    <div class="container">
        <form id='formulario' method='post' {% if formulario.is_multipart %} enctype="multipart/form-data" {% endif %} action=''>
            {% csrf_token %}
            <center>

                <label for="nota_pad_gris">Nota del pad Gris:</label>
                    <select id="nota_pad_gris" onchange="validar();">
                       {% for value in formulario.nota_pad_gris %}
                        <option value="hola">{{ value }}</option>
                        {% endfor %}
                    </select>

            <br><br>
            <p><input type='submit' class="btn btn-success btn-lg" value='Añadir'/>
             <a href="/ListadoCanciones/" type="input" class="btn btn-danger btn-lg">Cancelar</a></p>
            </center>
    </form>
    <br>
</div>  

编辑:

看看Nota del pad gris。这就是列表显示的内容。它显示了选择,但也显示了选择之间的空白。 [1]

这是我尝试提交表单时网络给我的错误

0 个答案:

没有答案