我现在用django框架制作筹款网站。在
但是,我在现场遇到了一些问题。 我做了不同级别的模特。在
我想用默认值。在
{{ form.funding }} ..... -> problem
(<input value="{{ funding.price }}">) -> want to same form of this.
有关详细信息,请参阅模板。在
例如
在模型.py在
^{pr2}$在表单.py在
class FundingForm(forms.models.ModelForm):
class Meta:
model = Funding
fields = ('funding', )
模板'融资.html'
{% for funding in fundings %}
<h3>{{ funding.price }}or more</h3>
<form method= "post" action="">
{{ form.funding }} ..... -> problem
(<input value="{{ funding.price }}">) -> want to same form of this.
{% csrf_token %}
{% if form.errors %}
<div class = "help-block">{{ form.funding.errors }}</div>
{% endif %}
<button id = "" type = "submit">funding</button>
</form>
{% endfor %}
在视图.py在
def view_funding(reqeust, project_id):
fundings = FundInfo.objects.filter(project= project_id)
form = PledgeForm() # How to use in here form = FundingForm(initial={'funding': form.funding.price})
return render(request, 'funding.html', {
'fundings': info,
'form': form
})
如果您想给表单字段指定一些初始值,那么在表单中使用
initial
这就是你如何给表单赋值的方法
相关问题 更多 >
编程相关推荐