如何将引导样式应用于自动生成的表单

Using beego render form to build html form https://beego.me/docs/mvc/view/view.md#renderform

type User struct {
Id    int         `form:"-"`
Name  interface{} `form:"username"`
Age   int         `form:"age,text,age:"`
Sex   string
Intro string `form:",textarea"`
}

<form action="" method="post">
{{.Form | renderform}}
</form>

This renders the form correctly but with poor html formatting enter image description here

What can I do to add bootstrap 4 stlying

Try adding class tags to the struct fields:

type User struct {
    Id    int         `form:"-"`
    Name  interface{} `form:"username" class:"form-control"`
    Age   int         `form:"age,text,age:" class:"form-control"`
    Sex   string
    Intro string      `form:",textarea" class:"form-control"`
}

<form action="" method="post">
    {{.Form | renderform}}
</form>

The exported func RenderForm calls parseFormTag for each field of the struct and gets variable class in the return (source code).

parseFormTag gets class from the class tag within the struct field tag (source code).

RenderForm then calls renderFormField for that field, passing in class. renderFormField adds class to the string that will eventually be used by RenderForm to create the HTML for the form (source code).