【问题标题】:Modal Form Connected to SQLite3连接到 SQLite3 的模态表单
【发布时间】:2021-04-04 03:30:57
【问题描述】:

我有以下代码,旨在显示数据表并允许用户通过单击 +New 按钮添加新行,这将打开一个具有正确表单的模式,然后用户点击提交和新行保存在表格中。

我正在努力将模态从静态、假数据转换为来自我的 SQLite3 数据库的数据。每当我尝试将我的字段(例如 { stakeholder.employee })添加到模式中时,我都会收到一个错误:

错误:

Invalid block tag on line 123: 'stakeholder.id'. Did you forget to register or load this tag?

现有数据表,顶部带有用于添加新行的按钮:

        <div class="col-md-12">
          <button type="button" class="btn btn-primary badge-pill float-right" style="font-size: 14px; width:80px;" data-toggle="modal" data-target="#new">+ New</button>
        </div>

   <table class="table table-hover" style="width:90% ">
      <thead>
        <tr style="font-family: Graphik Black; font-size: 14px">
          <th scope="col">#</th>
          <th scope="col">Employee</th>
          <th scope="col">Stakeholder Group</th>
          <th scope="col">Quadrant</th>
          <th scope="col">Description</th>
        </tr>
      </thead>
      <tbody>
        {% for stakeholder in stakeholder_list %}
        <tr style="font-family: Graphik;font-size: 12px">
          <td>{{ stakeholder.id }}</td>
          <td style="font-size: 15px">{{ stakeholder.employee }}</li></td>
          <td>{{ stakeholder.stakeholder_group }}</td>
          <td>{{ stakeholder.stakeholder_quadrant }}</td>
          <td>{{ stakeholder.description }}</td>
          <td><button type="button" class="btn btn-danger btn-sm badge-pill" style="font-size: 11px; width:60px" data-toggle="modal" data-target="#new">Edit</button></td>
        </tr>
        {% endfor %}
      </tbody>
    </table>

还有一个我正在尝试转换为表单的模态:

<div class="modal fade" id="new" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLongTitle">Customer Form</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">  
            {% csrf_token %}
    {{ form.non_field_errors }}
        <form>
          {% for field in form %}
          {% endfor %}

          <div class="form-group">
            <label for="exampleInputEmail1">Name</label>
            <input type="text" class="form-control" id="exampleInputEmail1" placeholder="Doe, John">
            <small id="emailHelp" class="form-text" style="color:red"><i>*Required Field</i></small>
          </div>  
          <br>
          <button type="submit" class="btn btn-primary">Submit</button>
        </form>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

models.py

class Stakeholder(models.Model):
    employee = models.CharField(max_length=200)
    stakeholder_group = models.CharField(max_length=200)
    description = models.CharField(max_length=200)
    stakeholder_quadrant = models.CharField(max_length=200)
    def __str__(self):
        return self.stakeholder

【问题讨论】:

    标签: javascript html jquery css django


    【解决方案1】:

    引发的错误:

    Invalid block tag on line 123: 'stakeholder.id'. Did you forget to register or load this tag?
    

    根据我的经验,可以在以下情况下提出:

    1. 文档中未闭合的标签
    2. 胡须变量 {% stakeholder.id %} 格式错误?
    3. 纠缠标签?

    因此,我建议您针对此类情况筛选模板。我敢打赌,这就是您的问题所在。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-11
      • 2016-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-08
      相关资源
      最近更新 更多