如何在Django中动态调整脆皮表单的大小

时间:2019-03-15 20:04:52

标签: django django-crispy-forms

我有一个显示为1行的表格。我希望窗口的大小根据输入的文本量动态扩展: enter image description here

这是它所在页面的html信息:

home.html

<div class="container">
  <div class="jumbotron jumbotron-fluid">
    <div class="row">
      <div class="col-md-6">
        {% if request.user.is_authenticated %}
          <form action="" method="POST">
            {% csrf_token %}
            {{ form2|crispy }}<br>
          <input type="submit" name="submit" value="Paste" id="submit" class="btn btn-primary">
          </form>
        {% endif %}
      </div>

forms.py

from django import forms
from pastes.models import Paste

class PostForm(forms.ModelForm):
    SYNTAX_CHOICES = {
        (0, "Plain"),
        (1, "Python"),
        (2, "HTML"),
        (3, "SQL"),
        (4, "Javascript"),
        (5, "CSS"),
    }

    class Meta:
        model       = Paste
        fields      = ('title', 'content', 'syntax', 'public')
        widgets = {"title": forms.TextInput(attrs={"class": "form-control"})}

0 个答案:

没有答案