方法一:读取上传的
参考:https://stackoverflow.com/questions/58288497/how-do-i-receive-an-excel-file-as-input-using-flask-and-read-it-using-openpyxl
html 代码:
<form action="{% url 'article_list_import' %}" method="POST" enctype="multipart/form-data">
{% csrf_token %}
<input type="file" id="article_list" name="article_list">
<input type="submit" value="Submit">
</form>
View.py 代码
def article_list_import(request):
if request.method == 'POST':
try:
article_list_file = request.FILES.get('article_list')
from openpyxl import load_workbook
wb = load_workbook(filename=article_list_file)
except:
pass
方法二:上传到临时文件路径
参考:https://www.jianshu.com/p/61ecb53acbf7