【发布时间】:2020-03-09 14:22:29
【问题描述】:
我只想显示我创建的表单中的一个字段,但出现“无法解析剩余部分:”错误
这是我的 forms.py 文件
from django import forms
from .models import *
class ProductForm(forms.ModelForm):
class Meta:
model = Product
fields = ('prod_name', 'company', 'quantity', 'price', 'units', 'prod_type')
这是我的 html 文件
{% extends 'base.html' %}
{% block body %}
<div class="container">
<form method="POST">
<br>
{% csrf_token %}
{% for field in form %}
{% if field.name=='units' %}
<div class ="form-form row">
<label for="id_{{field.name}}" class="col-2 col-form-label">{{field.label}}</label>
<div class ="col-10">
{{field}}
</div>
</div>
{% endif %}
{% endfor %}
<button type="submit" class="btn btn-primary" name="button">Update Sales</button>
</form>
</div>
{% endblock %}
我只想在我的网页中为我正在创建的这个模块显示单元
【问题讨论】:
-
为什么不制作一个只有一个字段的表单呢?这看起来更安全。
-
@WillemVanOnsem 谢谢...你的方法奏效了!