Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在Django的引导模式中打开新视图_Python_Django_Bootstrap Modal - Fatal编程技术网

Python 在Django的引导模式中打开新视图

Python 在Django的引导模式中打开新视图,python,django,bootstrap-modal,Python,Django,Bootstrap Modal,我的情况是,我有几个modals(确切地说是4个),应该可以在我的应用程序的每个视图中访问。我只举一个例子。让我们看看我如何在主屏幕视图上显示: base.html ...abbreviated... <a data-toggle="modal" href="#exampleModal">Shipment</buton> <!-- Modal --> <div class="modal fade" id="exampleModal" tabindex

我的情况是,我有几个modals(确切地说是4个),应该可以在我的应用程序的每个视图中访问。我只举一个例子。让我们看看我如何在主屏幕视图上显示:

base.html

...abbreviated...

<a data-toggle="modal" href="#exampleModal">Shipment</buton>

<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Create Shipment</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <form method="POST">
        {% csrf_token %}
      <div class="modal-body">
        {{shipmentForm|crispy}}
      </div>

      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="submit" name="shipment" class="btn btn-primary">Save changes</button>
      </form>
      </div>
    </div>
  </div>
</div>
<a data-toggle="modal" href="{% url 'CreateShipmentView' %}>Shipment</buton>
这工作得非常好,但问题是,我需要在我的应用程序中的每个视图中都包含来自HomeView的代码。那会让我重复很多次。我已经在我的base.html中包含了模态的html,这样我就不必重复了。但是,我想让启动模态的按钮看起来像这样,而不是像上面那样

base.html

...abbreviated...

<a data-toggle="modal" href="#exampleModal">Shipment</buton>

<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Create Shipment</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <form method="POST">
        {% csrf_token %}
      <div class="modal-body">
        {{shipmentForm|crispy}}
      </div>

      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="submit" name="shipment" class="btn btn-primary">Save changes</button>
      </form>
      </div>
    </div>
  </div>
</div>
<a data-toggle="modal" href="{% url 'CreateShipmentView' %}>Shipment</buton>
如果不使用django modal引导包,这怎么可能呢?我试过了,但它似乎非常敏感,我不喜欢它,所以我宁愿避免。有人能告诉我怎么做吗

def CreateShipmentView(request):
    if request.method == 'POST':
        shipment_form = CreateShipmentForm(request.POST)
        if shipment_form.is_valid():
            new_shipment = shipment_form.save()the user to the success page
            return redirect('ShipmentListView')

    shipmentForm = CreateShipmentForm()
    context = {
        'shipmentForm': shipmentForm,
    }
    return render(request, 'modal.html', context)