【发布时间】:2021-12-23 20:42:49
【问题描述】:
我在 django 做一个网站,但这是我第一次使用这个框架,所以我不太习惯。
我需要在数据库中保存一些信息,并且我需要从一些单选按钮中获取这些信息。
我尝试了很多方法来获取数据,但没有任何效果。
所以我想问一下如何从template,html 获取models.py 中的这些数据。
这是views.py中的代码:
def question1(request):
form = CHOICES(request.POST)
return render(request, 'question1.html', {'form': form})
这是模板question1.html:
<form class="form-inline" method='POST' action="" enctype='multipart/form-data'>{% csrf_token %}
{{form.NUMS}}
</form>
然后有forms.py中的表格:
NUMS = [
('one', 'one'),
('two', 'two'),
('three', 'three'),
('four', 'four'),
('five', 'fives'),
]
class CHOICES(forms.Form):
NUMS = forms.ChoiceField(choices=NUMS, widget=forms.RadioSelect)
然后我真的不知道如何在models.py 中执行该功能
【问题讨论】:
标签: python django django-models django-forms django-templates