问题描述
理想情况下,我想扩展我的字段在前端。他们必须更长的时间,就像从管理面板制作它们一样。目前他们看起来像这样:
Ideally I want to "expand" my fields on the frontend. They have to be way longer just like when you make them from in the admin-panel. Currently they look like this:
但是我想要这样描述(我的管理员是bootstrapped btw ):
However I want them portrayed like this (my admin is bootstrapped btw):
这是我的代码:
<div class="container">
<h1>Opret ny klient</h1>
<form method="POST" class="post-form">{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="btn btn-primary">Opret klient</button>
<button type="button" class="save btn btn-default">Tilbage til klienter</button>
</form>
</div>
底线
如何让我的表单看起来作为视觉吸引力,在我的管理面板中看起来如何?
The bottom lineHow do I make my form seem as visually appealing as it looks in my admin panel?
推荐答案
如果你寻找快速的方式,只需使用脆性表单
If you looking for fast way, just use crispy forms
http://django-crispy-forms.readthedocs.org/en/latest/install.html#installing-django-crispy-forms
pip install --upgrade django-crispy-forms
在settings.py: br>
INSTALLED_APPS =(
...
'crispy_forms',
)
in settings.py:INSTALLED_APPS = ( ... 'crispy_forms',)
在模板的顶部:
{%load crispy_forms_tags%}
和这样的呈现窗体 {%form | crispy%}
它默认使用 bootstrap
表单
at the top of template:{% load crispy_forms_tags %}
and render form like this {% form|crispy %}
it use bootstrap
form by default
如果您想要更多选项来呈现表单,您可以阅读有关的文档香脆。或者只是使用本机django表单,并渲染此表单的每个字段,如 {{form.your_field}}
If you want more options to render your form, you can read docs about crispy. Or just use native django forms, and render each field of this form, like {{ form.your_field }}
这篇关于如何在前端更改我的模型字段的外观?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!