0
我要訪問的形式的單個元素... 這裏是代碼:訪問各個表單字段
Models.py
class GatewayDetails(models.Model):
gateway_id = models.IntegerField(primary_key=True)
gateway_name = models.CharField(max_length=256L)
class Meta:
db_table = 'gateway_details'
class GatewayParameters(models.Model):
gateway = models.ForeignKey(GatewayDetails)
id=models.IntegerField(primary_key=True)
gateway_param1 = models.CharField(max_length=256L)
gateway_param2 = models.CharField(max_length=256L)
gateway_param3 = models.CharField(max_length=256L)
gateway_param4 = models.CharField(max_length=256L)
gateway_param5 = models.CharField(max_length=256L)
gateway_param6 = models.CharField(max_length=256L)
gateway_param7 = models.CharField(max_length=256L)
gateway_param8 = models.CharField(max_length=256L)
gateway_param9 = models.CharField(max_length=256L)
class Meta:
db_table = 'gateway_parameters'
views.py
if request.method=="POST":
add_gateway_details_form=Add_Gateway_Details(request.POST)
if add_gateway_form.is_valid():
success=True
else:
add_gateway_details_form=Add_Gateway_Details()
else:
add_gateway_details_form=Add_Gateway_Details()
add_gateway_parameters_form=Add_Gateway_Parameters()
forms.py
class Add_Gateway_Details(forms.ModelForm):
class Meta:
model=GatewayDetails
exclude=('gateway_id',)
class Add_Gateway_Parameters(forms.ModelForm):
class Meta:
model=GatewayParameters
exclude=('gateway',)
HTML:
<form action="." method="POST">
{{ add_gateway_details_form.as_p}}
{{ add_gateway_parameters_form.as_p }}
<input type="submit" value="send">
</form>
我要訪問的形式的單個元素(如:gateway_name,gateway_param1)不整形式與add_gateway_details_form.as_p或add_gateway_parameters_form.as_p
任何幫助的情況下。 。