Crispy表单文本输入高度(Django 1.9)

Crispy表单文本输入高度(Django 1.9),django,twitter-bootstrap-3,django-crispy-forms,Django,Twitter Bootstrap 3,Django Crispy Forms,我的输入文本字段用简洁的表单呈现,太高了。在所有示例中,我看到大多数文本字段的高度只有一个字符(这就是我想要的)。但我的输入字段要高得多。 我正在使用bootstrap3。 (见附图) 就我所见,我的基本模板没有什么特别之处。以下是主要部分: <body class="skin-black"> <!-- header logo: style can be found in header.less --> <header class="he

我的输入文本字段用简洁的表单呈现,太高了。在所有示例中,我看到大多数文本字段的高度只有一个字符(这就是我想要的)。但我的输入字段要高得多。 我正在使用bootstrap3。 (见附图)

就我所见,我的基本模板没有什么特别之处。以下是主要部分:

      <body class="skin-black">
    <!-- header logo: style can be found in header.less -->
    <header class="header">
        <a href="/" class="logo">
        <img src="{% static 'portal/logo.png' %}" alt="Logo"/>
        </a>
        <!-- Header Navbar: style can be found in header.less -->
        <nav class="navbar navbar-static-top" role="navigation">
            <!-- Sidebar toggle button-->
            <a href="#" class="navbar-btn sidebar-toggle" data-toggle="offcanvas" role="button">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </a>
            <div class="navbar-right">
                {% if user.is_authenticated %}
                    <a href="/logout"><span class="glyphicon glyphicon-log-out"></span> Logout {{ user.username }} </a>
                {% else %}
                    <a href="/registration/login"><span class="glyphicon glyphicon-log-in"></span> Login</a>
                {% endif %}
            </div>
        </nav>
    </header>
            <div class="wrapper row-offcanvas row-offcanvas-left">
                <!-- Left side column. contains the logo and sidebar -->
                <aside class="left-side sidebar-offcanvas">
                    <!-- sidebar: style can be found in sidebar.less -->
                    <section class="sidebar">
                        <!-- Sidebar user panel -->
                        <div class="user-panel"></div>
                    </section>
                       <!-- sidebar menu: : style can be found in sidebar.less -->
                    {% if user.is_authenticated %}
                        <div id="MainMenu">
                          <div class="list-group panel">
                              {% for group in user.groups.all %}
                                {% if not group.name == 'client' %}
                                    <a href="/" class="list-group-item">Home</a>
                                    <a href="/modules" class="list-group-item">Modules</a>
                                {% endif %}
                              {% endfor %}
                            </div>
                          </div>
                    {% endif %}
                    </aside>

            <aside class="right-side">
                <section class="content">
                    <div class="wrapper">
                        <div class="row">
                            {% block content %}{% endblock %}
                        </div>
                    </div>
                </section>


            <div class="footer-main navbar-default navbar-fixed-bottom" id="footer">
                Copyright &copy NOZHUP, 2016
            </div>
            </aside><!-- /.right-side -->


    </div>
models.py:

from __future__ import unicode_literals
from django.db import models

# Create your models here.
class Module(models.Model):
    name = models.TextField(null=True)
    version = models.TextField(null=True)
    description = models.TextField(null=True)

    def __unicode__(self):  # __unicode__ on Python 2
        return self.name


class Category(models.Model):
    name = models.TextField(null=True)
    module = models.ForeignKey(Module, on_delete=models.CASCADE)

    def __unicode__(self):  # __unicode__ on Python 2
        return self.name

class Case(models.Model):
    name = models.TextField(null=True)
    action = models.TextField(null=True)
    desiredresult = models.TextField(null=True)
    category = models.ForeignKey(Category, on_delete=models.CASCADE)

    def __unicode__(self):  # __unicode__ on Python 2
        return self.name

class Suite(models.Model):
    name = models.TextField(null=True)
    description = models.TextField(null=True)
    cases = models.ManyToManyField(Case)
    untested = models.IntegerField(default=0)
    passed = models.IntegerField(default=0)
    failed = models.IntegerField(default=0)

    def __unicode__(self):  # __unicode__ on Python 2
        return self.name
模块_edit.html:

{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block content %}
<h4>Modules</h4>
{% crispy form %}
{% endblock %}
{%extends“base.html”%}
{%load crispy_forms_tags%}
{%block content%}
模块
{%crispy form%}
{%endblock%}

我认为您错误地使用了
models.TextField
而不是
models.CharField
。通常模型大多具有
CharField
,只有少数几个字段是
TextField
TextField
用于较长的、可能是多行的、可能是富文本的内容。我怀疑您是否希望
模块
名称或
模块
版本为多行。即使是
说明
也可能不需要(您的业务需要可以说明这一点)


您在教程中通常看到的文本输入字段是
我认为您错误地使用了
模型.TextField
而不是
模型.CharField
。通常模型大多具有
CharField
,只有少数几个字段是
TextField
TextField
用于较长的、可能是多行的、可能是富文本的内容。我怀疑您是否希望
模块
名称
模块
版本为多行。即使是
说明
也可能不需要(您的业务需要可以说明这一点)


教程中常见的文本输入字段是
请发布表单类的代码。您需要发布
forms.py
类和
models.py
类。您可能使用了错误的小部件来呈现组件。另外,如果您使用的是crispy表单,我在您发布的模板中找不到
{%load crispy\u forms\u tags%}
。这意味着你没有使用脆的形式为rendering@Cheng:如您所见,我在子模板中使用了标记…请发布表单类的代码。您需要发布
forms.py
类和
models.py
类。您可能使用了错误的小部件来呈现组件。另外,如果您使用的是crispy表单,我在您发布的模板中找不到
{%load crispy\u forms\u tags%}
。这意味着你没有使用脆的形式为rendering@Cheng:如你所见,我在子模板中使用标记…工作起来像个符咒。非常感谢。工作得很有魅力。非常感谢。
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block content %}
<h4>Modules</h4>
{% crispy form %}
{% endblock %}
self.fields['description'].widget = forms.Textarea(attrs={'rows': 4, 'cols': 25})