rod*_*ing 4 html python django
I cant seem to find ANYWHERE on how to do choicefield HTML tags in Django. I found radio buttons and other advance choice fields, but nothing on basic drop down HTML tags with Django. I have models.py
and view.py
set up passing list1
to the html
pages, but cant seem to make it display anything except
<select style="width:300px">
{% for choice in list1.VIEWS %}
<option>{{choice}}</option>
{{choice}}
{% endfor %}
</select>
Run Code Online (Sandbox Code Playgroud)
Help would be greatly appreciated
class preset_list(models.Model):
VIEWS = (
('1', 'X'),
('2', 'Y'),
)
query_choice = forms.ChoiceField(choices=VIEWS)
Run Code Online (Sandbox Code Playgroud)
list1 = models.preset_list()
return render_to_response('services.html',
{'array':json.dumps(data, cls=SpecialEncoder),
'list1':list1},
)
Run Code Online (Sandbox Code Playgroud)
ModelForms是你的朋友.
class PresetList(models.Model):
VIEWS = (
('1', 'X'),
('2', 'Y'),
)
query_choice = forms.ChoiceField(choices=VIEWS)
Run Code Online (Sandbox Code Playgroud)
from django.forms import ModelForm
from . import models
class PresetListForm(ModelForm):
class Meta:
model = models.PresetList
Run Code Online (Sandbox Code Playgroud)
from . import forms
def my_view(request):
preset_form = forms.PresetListForm()
return render_to_response('services.html', {
'array': json.dumps(data, cls=SpecialEncoder),
'preset_form': preset_form,
})
Run Code Online (Sandbox Code Playgroud)
<form method=POST action="/somewhere">
{{ preset_form.as_p }}
</form>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5269 次 |
最近记录: |