第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Django表單未出現(xiàn)在模板上

Django表單未出現(xiàn)在模板上

一只萌萌小番薯 2022-09-20 16:45:40
我目前正在從事一個(gè)需要Django Forms的項(xiàng)目,但我最終遇到了一些問(wèn)題。我的表單根本不顯示...我的模板上未顯示任何字段。所以我的代碼:models.pyclass Place(models.Model):    name = models.CharField(max_length=255)    longitudeMax = models.DecimalField(max_digits=8, decimal_places = 4 ,blank=True)    longitudeMin = models.DecimalField(max_digits=8, decimal_places = 4, blank=True)    latitudeMax = models.DecimalField(max_digits=8, decimal_places = 4, blank=True)    latitudeMin = models.DecimalField(max_digits=8, decimal_places = 4, blank=True)    datasetPath = models.CharField(max_length=255)    isActive = models.BooleanField(default=True)    def __str__(self):        return self.name    def get_place(self, name):        return Noneforms.pyclass NewPlaceForm(forms.Form):    name = forms.CharField(        widget=forms.TextInput(            attrs={                "placeholder" : "Name",                                "class": "form-control"            }        ))    longMax = forms.DecimalField(        widget=forms.NumberInput(            attrs={                "placeholder" : "Longitude Max",                                "class": "form-control"            }        ))    longMin = forms.DecimalField(        widget=forms.NumberInput(            attrs={                "placeholder" : "Longitude Min",                                "class": "form-control"            }        ))    latMax = forms.DecimalField(        widget=forms.NumberInput(            attrs={                "placeholder" : "Latitude Max",                                "class": "form-control"            }        ))    latMin = forms.DecimalField(        widget=forms.NumberInput(            attrs={                "placeholder" : "Latitude Min",                                "class": "form-control"            }        ))    class Meta:        model = Place        fields = ('name', 'longitudeMax', 'longitudeMin', 'latitudeMax', 'latitudeMin')]
查看完整描述

1 回答

?
繁花如伊

TA貢獻(xiàn)2012條經(jīng)驗(yàn) 獲得超12個(gè)贊

Django處理開(kāi)箱即用的表單呈現(xiàn),要顯示基本表單,請(qǐng)嘗試:


  <form method="POST" action="{% url 'namespaced:url' %}">

    { csrf_token %}

    {{ form.as_p }}

    <input type="submit" value="submit">

  </form>

也就是說(shuō),看起來(lái)您正在模板中使用引導(dǎo),您可能會(huì)發(fā)現(xiàn)該包很有用(https://github.com/zostera/django-bootstrap4)。django-bootstrap4


快速示例:


pip install django-bootstrap4


并添加到已安裝的應(yīng)用。bootstrap4


然后在您的模板中:


{% load bootstrap4 %}


{# Load CSS and JavaScript #}

{% bootstrap_css %}

{% bootstrap_javascript jquery='full' %}




<form action="{% url 'namespaced:url' %}" method="post" class="form">

  {% csrf_token %}

  {% bootstrap_form form %}

  {% buttons %}

    <button type="submit" class="btn btn-primary">

      Submit

    </button>

  {% endbuttons %}

</form>

如果需要,可以使用: 手動(dòng)呈現(xiàn)每個(gè)字段,因此您可以執(zhí)行類似 之類的操作來(lái)手動(dòng)排列頁(yè)面上的表單字段。{% bootstrap_field field %}<div class="col-md-6">{% bootstrap_field my_field %}</div>


查看完整回答
反對(duì) 回復(fù) 2022-09-20
  • 1 回答
  • 0 關(guān)注
  • 87 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)