亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么我不能在 django 中使用 pandas 指定媒體文件夾中的文件位置?

為什么我不能在 django 中使用 pandas 指定媒體文件夾中的文件位置?

慕后森 2023-07-27 14:06:44
我試圖讓 pandas 從媒體文件夾中讀取文件作為read_excel(). 這是我嘗試過的:from django.shortcuts import renderfrom .models import Benchmarkimport pandas as pd# Create your views here.def main_view(request):    file = pd.read_excel('media/uploads/benchmarks/benchmarks_for_website.xlsx', index_col=0)    context = {        'df': file.to_html()    }    return render(request, 'main.html', context)它可以編譯,但是當我嘗試在瀏覽器中訪問 html 頁面時,出現以下錯誤:FileNotFoundError at /benchmarks/ [Errno 2] 沒有這樣的文件或目錄:“media/uploads/benchmarks/benchmarks_for_website.xlsx”我究竟做錯了什么?另外,我還有MEDIA_ROOT和MEDIA_URL:MEDIA_URL = '/media/'MEDIA_ROOT = '/home/user/project/media'很感謝任何形式的幫助!
查看完整描述

1 回答

?
浮云間

TA貢獻1829條經驗 獲得超4個贊

因此,經過一天的進一步嘗試,我決定測試一下將實際的網站網址放在該media位之前。所以最終它看起來是這樣的:


from django.shortcuts import render

from .models import Benchmark

import pandas as pd


# Create your views here.


def main_view(request):

    file = pd.read_excel('https://url.com/media/uploads/benchmarks/benchmarks_for_website.xlsx', index_col=0)

    context = {

        'df': file.to_html()

    }

    return render(request, 'main.html', context)

我猜這不是“正確”的做法,但它對我有用。請隨時評論更好的解決方案!


查看完整回答
反對 回復 2023-07-27
  • 1 回答
  • 0 關注
  • 116 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號