[英]How to add crispy forms to bootstrap4 in Django?
我無法將引導上傳表單與 django 表單(脆表單)結合起來。 知道如何將酥脆的 forms 放入引導程序形式。
這是 django 脆皮 forms
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form|crispy }}
<button type="submit" class="btn btn-primary">Upload and Download!</button>
</form>
這是我想放脆形式的引導形式。
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> <div class="custom-file"> <input type="file" class="custom-file-input" id="customFile"> <label class="custom-file-label" for="customFile">Choose file</label> </div>
知道如何將這兩者結合起來嗎?
你可以做這樣的事情
<form action="." method='POST' enctype="multipart/form-data">
{% csrf_token %}
<div class="custom-file">
<input type="file" class="custom-file-input" name="file" id="customFile">
<label class="custom-file-label" for="customFile">Choose file</label>
</div> <br><br>
<button type="submit" class="btn btn-primary">Upload and Download!</button>
</form>
並將其添加到頁面的頭部
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
並在您的views.py 中獲取文件,您可以使用files = request.Files['file']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.