Python 如何使用django中的filesystemstorage从上传的文件中提取数据?
嗨,我正在学习python 我尝试使用FileSystemStorage defualt类上载一个文件,该类在django中是defualt类,文件正在上载,但我想从上载的文件中提取数据,该文件存储在媒体文件夹中,如名称:“soso” 年龄:“所以” views.py:Python 如何使用django中的filesystemstorage从上传的文件中提取数据?,python,django,file-system-storage,Python,Django,File System Storage,嗨,我正在学习python 我尝试使用FileSystemStorage defualt类上载一个文件,该类在django中是defualt类,文件正在上载,但我想从上载的文件中提取数据,该文件存储在媒体文件夹中,如名称:“soso” 年龄:“所以” views.py: from django.shortcuts import render from django.conf import settings from django.core.files.storage import FileSys
from django.shortcuts import render
from django.conf import settings
from django.core.files.storage import FileSystemStorage
def index(request):
if request.method == 'POST' and request.FILES['myfile']:
myfile = request.FILES['myfile']
fs = FileSystemStorage()
filename = fs.save(myfile.name, myfile)
uploaded_file_url = fs.url(filename)
return render(request, 'index.html', {
'uploaded_file_url': uploaded_file_url
})
return render(request, 'index.html')
index.html:
{% block content %}
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
<input type="file" name="myfile">
<button type="submit">Upload</button>
</form>
{% if uploaded_file_url %}
<p>File uploaded at: <a href="{{ uploaded_file_url }}">{{ uploaded_file_url }}</a></p>
{% endif %}
<p><a href="{% url 'home' %}">Return to home</a></p>
{% endblock %}
{%block content%}
{%csrf_令牌%}
上传
{%如果上载了\u文件\u url%}
文件上载于:
{%endif%}
{%endblock%}
{% block content %}
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
<input type="file" name="myfile">
<button type="submit">Upload</button>
</form>
{% if uploaded_file_url %}
<p>File uploaded at: <a href="{{ uploaded_file_url }}">{{ uploaded_file_url }}</a></p>
{% endif %}
<p><a href="{% url 'home' %}">Return to home</a></p>
{% endblock %}