django - 使用 Apache 服务时找不到 Django 文件
问题描述
我使用 Linode 在 Linux 服务器上部署了我的 Django 项目。当我通过python manage.py runserver
端口 8000 上的命令运行它时,一切看起来都很好。但是,当我使用 apache2 时,加载网站时出现以下错误:
FileNotFoundError at /
[Errno 2] No such file or directory: 'research_files/data.xlsx'
Request Method: GET
Request URL: http://453.33.13.202/
Django Version: 3.1.5
Exception Type: FileNotFoundError
Exception Value:
[Errno 2] No such file or directory: 'research_files/data.xlsx'
在 /etc/apache2/sites-available 我创建了一个 django_project.conf 文件,其中包含以下说明:
Alias /research_files/ /home/alexa/django_project/research_files/
<Directory /home/alexa/django_project/django_project/research_files>
Require all granted
</Directory>
<Directory /home/alexa/django_project/django_project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias / /home/alexa/django_project/django_project/wsgi.py>
WSGIDaemonProcess django_app python-path=/home/alexa/django_project python-home=/home/alexa/django_project/venv
WSGIProcessGroup django_app
然后我通过运行启用了该文件,sudo a2ensite django_project
并通过运行授予了对该文件夹的访问权限:
sudo chown :www-data django_project/research_files
sudo chmod 664 django_project/research_files
什么可能导致此错误?
解决方案
也许是在 research_files 之后的第一行中的额外 /,因此 /research_files/ 将是 /research_files。这也可能是一个指南https://stackoverflow.com/a/5684257/15020017
推荐阅读
- java - 如何通过指定类而不是 jar 来加载代理
- java - 如何在 Spring Boot 应用程序中使用多个 mongodb 数据库?
- parsing - Convert String into exact same Int
- c# - 如何检查 customLogs 是否正在上传到 Azure Application Insights
- excel - 根据值更改散点图excel中特定点的形状
- php - 如何使用ffmpeg将具有过渡效果的文本添加到视频中?
- javascript - 如何在 multidatepicker 中添加禁用日期的描述
- linux - 我想替换 UNIX 文件第 6 列中的一个字符,这似乎有点挑战性
- c - 在 cpu 模拟器中是调用外部函数所需的程序集
- python-3.x - 如何从命令行运行没有模块的python