程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Using the bootstrap style in HTML in Django

編輯:Python

######bootstrap In the style input Whether the box has applied the effect ( Some have effect )

class AdminModelForm(forms.ModelForm): class Meta: model = models.Admin fields = "__all__" def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) for name, field in self.fields.items(): if field.widget.attrs: field.widget.attrs['class'] = "form_control" field.widget.attrs['placeholder'] = field.label else: field.widget.attrs = { "class": "form-control", "placeholder": field.label }def admin_add(request): form = AdminModelForm() context = { "form": form, "title": " New administrator " } return render(request, "change.html", context)
<!--change.html Part of the code --><div class="panel-body"> <form method="post" novalidate> {% csrf_token %} {% for field in form %} <div class="form-group"> <label>{
{ field.label }}</label> {
{ field }} <span >{
{ field.errors }}</span> </div> {% endfor %} <button type="submit" class="btn btn-primary"> Submit </button> </form> </div>

html Check the screenshot

My solution ideas and tried methods
What I want to achieve

similar

This is from another page , Also used. form-control, But there was an effect




Take the answer :

Wrong style name , Should be form-control, Middle bar line . At the same time confirm bootstrap Of css Correctly imported , Path is correct



  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved