如何设置FilePond JS图像预览

时间:2019-02-13 13:05:15

标签: javascript python django filepond

我正在尝试使用FilePond来允许用户上传拖放图像。我已经设置了FilePond拖放功能,并且正在尝试实现图像预览功能。我已经附加了css和js并将其包含在我的html中。图片预览仍然无法正常工作。

{% extends 'main/dashboardbase.html'%}
{% block content %}
{% load static %}
<!doctype html>
<html lang="en">
 <head>
 <!-- Required meta tags -->
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-tofit=no">
<link rel="stylesheet "type="text/css" href="{% static 'main/add.css'%}">
<link rel="stylesheet "type="text/css" href="{% static 'main/filepond.css'%}">
<link rel="stylesheet" type="text/css" href="{% static 'main/filepond-plugin-image-preview.css'%}">
 </head>
 <body>
  <button type="submit" id="add">Save</button>
  <a href="{% url 'main:products'%}">
    <button id="cancel" >Cancel</button>
  </a>
  <div class="col-sm-12 col-lg-6" id="inner">
    <form method="POST" enctype="multipart/form-data" id="inputform" name="form1">
        {% csrf_token %}
        <h4>Title</h4>
        <input type="text" name="product_title" id="product_title" placeholder="Give your product a name">
        <h4>Price</h4>
        <input type="text" name="product_price" id="product_price" placeholder="0.00">
        <h4>Description</h4>
        <input type="text" name="product_description" id="product_description" placeholder="Write a description about your product">
        <input type="file" name="product_images">
    </form>

  </div>
    <script type="text/javascript" src="{% static 'main/add.js'%}"></script>
    <script src="{% static 'main/filepond-plugin-image-preview.js'%}"></script>
    <script src="{% static 'main/filepond.js'%}"></script>
    <script>
        const inputElement = document.querySelector('input[type="file"]');
        const pond = FilePond.create(inputElement);

        FilePond.setOptions({
          server: '#'
        });
    </script>
 </body>
</html>

{% endblock%}

1 个答案:

答案 0 :(得分:0)

确保已加载“ filepond-plugin-image-preview.min.css”。那是我的问题。