脆皮形式的定制场地django不起作用
我想显示一个表格来创建帖子。我使用Crispy-Form,目前显示:
使用html模板:
{% extends 'blog_app/base.html' %}
{% load crispy_forms_tags %}
{% block content %}
<div class="content-section">
<form method="POST">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Create Post</legend>
{{ form.media }}
{{ form|crispy }}
</fieldset>
<div class="form-group">
<button class="btn btn-outline-info" type="submit">Post</button>
</div>
</form>
</div>
{% endblock %}
我想增加标题框的大小并减小内容框的大小,以便我适合内容部分。
我尝试的是:
- 在模板中,将每个字段显示为带有指定CSS类的脆性字段:
{% block content %}
<div class="content-section">
<form method="POST">
{% csrf_token %}
<div class="form-group col-md-8">
{{ form.title|as_crispy_field }}
</div>
<div class="form-group col-md-8">
{{ form.content|as_crispy_field }}
</div>
<div class="form-group">
<button class="btn btn-outline-info" type="submit">Post</button>
</div>
</form>
</div>
{% endblock %}
- 在表单类中,设置助手和布局:
class PostCreateForm(forms.ModelForm):
class Meta:
model = Post
fields = ['title', 'content']
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.layout = Layout(
Field('title', id="form-title", css_class="col-md-8", name="title"),
Field('content', id="form-content", css_class="col-md-8", name="title"))
在这两种方面,什么都没有改变。 有人可以给我指针吗?
更新:
对于内容框,由于我使用ckeditor的Richtextfield,因此当我将以下配置添加到settings.py
时,它的大小确实会更改以适合内容部分。但是我仍然不知道如何更改标题框的大小。
CKEDITOR_CONFIGS = {
'default': {
'height': '100%',
'width': '100%',
},
}
i want to display a form to create posts. i use crispy-form and it currently displays:
with html template:
{% extends 'blog_app/base.html' %}
{% load crispy_forms_tags %}
{% block content %}
<div class="content-section">
<form method="POST">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Create Post</legend>
{{ form.media }}
{{ form|crispy }}
</fieldset>
<div class="form-group">
<button class="btn btn-outline-info" type="submit">Post</button>
</div>
</form>
</div>
{% endblock %}
i want to increase size of the title box and reduce size of the content box so that i fits the content section.
what i tried:
- in template, display each field as crispy field with specified css class:
{% block content %}
<div class="content-section">
<form method="POST">
{% csrf_token %}
<div class="form-group col-md-8">
{{ form.title|as_crispy_field }}
</div>
<div class="form-group col-md-8">
{{ form.content|as_crispy_field }}
</div>
<div class="form-group">
<button class="btn btn-outline-info" type="submit">Post</button>
</div>
</form>
</div>
{% endblock %}
- in form class, set helper and layout:
class PostCreateForm(forms.ModelForm):
class Meta:
model = Post
fields = ['title', 'content']
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.layout = Layout(
Field('title', id="form-title", css_class="col-md-8", name="title"),
Field('content', id="form-content", css_class="col-md-8", name="title"))
in both ways, nothing changes.
can someone give me a pointer?
update:
for the content box, since i used RichTextField from ckeditor for it, when i add the below config to settings.py
, the size of it does change to fit the content section. but i still have no idea how to change size of the title box.
CKEDITOR_CONFIGS = {
'default': {
'height': '100%',
'width': '100%',
},
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保您在
settings.py
中具有正确的模板包:...并在布局中使用列和行(以helper的形式,不是直接以表单为单位):
下一步,使用
脆皮
TemplateTag:Ensure that you have the correct template pack in your
settings.py
:...and use your columns and rows in the layout (in the form helper, not directly in the form):
Next, use the
crispy
templatetag: