Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/375.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

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
Javascript 如何将FilePond指向django媒体文件_Javascript_Django_Filepond - Fatal编程技术网

Javascript 如何将FilePond指向django媒体文件

Javascript 如何将FilePond指向django媒体文件,javascript,django,filepond,Javascript,Django,Filepond,我使用FilePond.js允许用户在网站上拖放图像。我正在尝试设置FilePond以检索用户照片输入。显然,我是想把我想要的照片上传到哪里的媒体链接。像这样: <script> FilePond.registerPlugin(FilePondPluginImagePreview); const inputElement = document.querySelector('input[type="file"]'); const pond

我使用FilePond.js允许用户在网站上拖放图像。我正在尝试设置FilePond以检索用户照片输入。显然,我是想把我想要的照片上传到哪里的媒体链接。像这样:

 <script>
    FilePond.registerPlugin(FilePondPluginImagePreview);
    const inputElement = document.querySelector('input[type="file"]');
    const pond = FilePond.create(inputElement);

    FilePond.setOptions({
      server: "#" *** I have tried everthing possible as a server option, nothing works***
    });
</script>


def add(request):
if request.method == "POST":
    product_title = request.POST.get("product_title")
    product_price = request.POST.get("product_price")
    product_description = request.POST.get("product_description")
    product_images = request.FILES.getlist('filepond')
    request.user.product_set.create(product_title = product_title,product_price =product_price, product_description = product_description, product_images = product_images)
return render(request,"main/add.html")


class product(models.Model):
  user = models.ForeignKey(User, on_delete=models.CASCADE)
  product_title =  models.CharField(max_length=100, blank=True)
  product_price =  models.CharField(max_length=30, blank=True)
  product_description =  models.CharField(max_length=1000, blank=True)
  product_images = models.FileField()

registerPlugin(FilePondPluginImagePreview);
const inputElement=document.querySelector('input[type=“file”]”);
const pond=FilePond.create(inputElement);
FilePond.setOptions({
服务器:“#”***作为服务器选项,我已经尝试了所有可能的方法,但没有任何效果***
});
def添加(请求):
如果request.method==“POST”:
product\u title=request.POST.get(“product\u title”)
产品价格=request.POST.get(“产品价格”)
产品描述=request.POST.get(“产品描述”)
product_images=request.FILES.getlist('filepond'))
request.user.product\u set.create(产品名称=产品名称,产品价格=产品价格,产品描述=产品描述,产品图像=产品图像)
返回呈现(请求“main/add.html”)
类别产品(型号.型号):
user=models.ForeignKey(用户,on_delete=models.CASCADE)
product_title=models.CharField(最大长度=100,空白=True)
product_price=models.CharField(最大长度=30,空白=True)
产品描述=models.CharField(最大长度=1000,空白=True)
product_images=models.FileField()
但我似乎无法让FilePond将图像上传到Django媒体url

如何将FilePond上传到我的照片所在的url 要储存吗

我知道如何从用户输入中收集图像的唯一方法是使用get请求。我还可以使用get请求仅检索用户提交的FilePond图像,并以这种方式将其上载到数据库吗

另外,我正试图指向FilePond将其上传到我网站上的媒体url 开发服务器。那是


后端脚本处理
/media
应接受来自名为
filepond
的字段的POST请求。看

看看下面的示例,我想这就是在Django中检索文件的方式:

request.FILES['filepond']
如果该字段设置为
multiple

files = request.FILES.getlist('filepond')

因此,如果您相应地调整Django脚本,您应该会看到文件对象出现在后端。

我为Django编写了一个小助手应用程序:

它允许您通过上载路径指定上载所针对的应用程序,您可以编写自定义上载处理程序,然后将上载的文件与正确的模型相匹配


它还处于早期阶段,但可能会有所帮助。

如果使用此方法,是否仍需要在服务器选项中指定某些内容?因为我试过了,但得到的是一个空列表。服务器选项必须指向后端脚本位置谢谢我找到了它。请向可能有相同问题的未来用户投票。您可以这样做: