Python 为什么可以';我是否在django中使用pandas从媒体文件夹中指定文件位置?

Python 为什么可以';我是否在django中使用pandas从媒体文件夹中指定文件位置?,python,django,pandas,django-views,django-templates,Python,Django,Pandas,Django Views,Django Templates,我正在尝试让pandas以read\u excel()的形式从媒体文件夹中读取文件。 这就是我尝试过的: 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('media/uploads/benchmarks/benchmar

我正在尝试让pandas以
read\u excel()
的形式从媒体文件夹中读取文件。 这就是我尝试过的:

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('media/uploads/benchmarks/benchmarks_for_website.xlsx', index_col=0)
    context = {
        'df': file.to_html()
    }
    return render(request, 'main.html', context)
它可以编译,但当我尝试在浏览器中访问html页面时,会出现以下错误:

FileNotFoundError位于/benchmarks/[Errno 2]没有这样的文件或目录:“media/uploads/benchmarks/benchmarks\u for_website.xlsx”

我做错了什么?此外,我还有
MEDIA\u ROOT
MEDIA\u URL

MEDIA_URL = '/media/'
MEDIA_ROOT = '/home/user/project/media'

非常感谢您的帮助

因此,经过一天的进一步尝试,我决定先测试实际的网站url,然后再测试
媒体。所以最后它看起来是这样的:

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)

我猜这不是“正确”的方法,但对我来说很有效。请随意评论一个更好的解决方案

因此,经过一天的进一步尝试,我决定先测试实际的网站url,然后再测试
媒体。所以最后它看起来是这样的:

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)
我猜这不是“正确”的方法,但对我来说很有效。请随意评论一个更好的解决方案