python - 如何使用 django 中的 filesystemstorage 从上传的文件中提取数据?
问题描述
你好我正在学习python
我尝试使用 FileSystemStorage defualt 类上传文件,该类是 django 中的默认类,文件正在上传,但我想从上传的文件中提取数据,该文件正在存储媒体文件夹,如名称:“soso” 年龄:“so”
the code which I tried so far is as below
视图.py:
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')
索引.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 %}
解决方案
推荐阅读
- gitlab - 使用 gitlab 页面托管多个测试报告
- java - 路径变量值中存在@符号时未选择请求参数
- dns - Informatica 工作流(MS SQL SERVER 数据源和目标)失败,错误 RR_4036“未找到数据源名称且未指定默认驱动程序。”
- consensus - 当跟随者在 raft 中失败时,领导者重试的详细信息
- php - 通过 PHP7.2 laravel 连接到 mongodb 时,出现以下错误:
- ffmpeg - 从帧索引ffmpeg中提取视频或音频
- amazon-web-services - `aws eks list-nodegroups` 和 `eksctl get nodegroups` 的结果不一致
- sql - 多次插入失败后的 ORA-02049
- mpi - 让 OpenMp 的每个线程使用一个核心,当被 mpirun 启动时
- python - 如何将区分系列结果从熊猫数据框中的索引 0 添加到另一列?