Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.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/0/azure/13.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 - Fatal编程技术网

Python 我想使用django通过一个提交按钮上传一组多个文件

Python 我想使用django通过一个提交按钮上传一组多个文件,python,django,Python,Django,我想使用django通过一个提交按钮上传一组多个文件。我面临的问题是上传的文件不会保存在本地机器的任何地方。 谁能帮我一下吗 我的代码是: urls.py from django.urls import path from django.conf import settings from django.conf.urls.static import static from . import views urlpatterns = [ path('', views.home, n

我想使用django通过一个提交按钮上传一组多个文件。我面临的问题是上传的文件不会保存在本地机器的任何地方。 谁能帮我一下吗

我的代码是:

urls.py 

from django.urls import path
from django.conf import settings
from django.conf.urls.static import static 

from . import views

urlpatterns = [
    path('', views.home, name='home'),
    path('majorheads/', views.display_majorheads, name='majorheads'),
    path('upload/', views.display_uploadpage, name='displayupload'),
 ]
 
if settings.DEBUG:
    urlpatterns + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
views.py

from django.shortcuts import render
from django.http import HttpResponse
from django.core.files.storage import FileSystemStorage

def display_uploadpage(request):
    return render(request, 'website/upload.html' )
    if request.method == 'POST':
        uploaded_file = request.FILES['files']
        fs = FileSystemStorage()
        fs.save(uploaded_file.name, uploaded_file)

    return render(request, 'upload.html') 
设置.py

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
upload.html

<form method="post" enctype="multipart/form-data"> 
                        {% csrf_token %}
                            <div class="form-group"> 
                              <div class="container"> 
                                
                                <div class="row"> 
                                    <div class="col"> 
                                      <label>Select AG Data...</label>
                                      <input type="file" id="files" name="files" multiple="multiple"> 
                                    </div> 
                                    <div class="col"> 
                                      <label>Select fin year</label>
                                      <input type="text" id="datepicker"/> 
                                    </div> 
                                </div>
                              </div>
                           </div>
                        </form>

{%csrf_令牌%}
选择AG数据。。。
选择财务年度

Hi,
return render(请求,'website/upload.html')
将跳过其他所有内容Hello,非常感谢。成功了。