【问题标题】:Python, Django: getting full path from filePython,Django:从文件中获取完整路径
【发布时间】:2021-01-01 18:35:30
【问题描述】:

晚上好,

我正在尝试通过模板中的 input 选择一个文件(“example.csv”):

ma​​in.html

...
<form method="post" enctype="multipart/form-data">
    {% csrf_token %}
    <input type="file" name="myFile">
    <button class="btn btn-success" type="submit">Choose</button>
</form>
...

选择并点击按钮后,我想实现完整路径加上文件本身的名称作为字符串!

views.py

...
if request.method == 'POST' and request.FILES['myFile']:
    myFile = request.FILES['myFile']
    file_path = # getting the full file path
...

例如:

  • data_name = 'example.csv'
  • file_path = 'C:\Users\John Doe\Files'

所以字符串应该如下所示:'C:\Users\John Doe\Files\example.csv'

我用 os.path 尝试过,但这似乎不起作用,或者我在这里做错了什么!?

感谢您的帮助!

【问题讨论】:

  • file_path 到底是什么来历?

标签: python django file input path


【解决方案1】:

无法获取用户文件的本地路径,浏览器不提供此类信息。通常你得到的信息是大小、类型、文件名。

检查ThisThisThis

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-17
    • 2018-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-11
    • 2011-06-24
    相关资源
    最近更新 更多