gpt4 book ai didi

python - 无法加载静态数据,Apache、Windows 上的 Django Rest_framework

转载 作者:行者123 更新时间:2023-12-01 02:45:38 24 4
gpt4 key购买 nike

所以,我正在尝试学习 django,并尝试通过 mod_wsgi 在 Apache 服务器上制作一个带有 Angular 和 Django REST 后端的应用程序。目前,我遇到了静态文件的问题。当应用程序在 127.0.0.1:8000 上使用 Django 工具运行时一切正常,但是当我通过 Apache 加载它时 - 我缺少静态数据,因此输出看起来非常原始:

enter image description here

我尝试使用manage.pycollectstatics收集静态数据,尝试在python目录中定义一个包含静态数据的目录 - 什么也没得到:

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'DjangoApp/static/')

STATICFILES_DIRS = [
'C:/Users/<user>/AppData/Local/Programs/Python/Python36-32/Lib/site-packages/rest_framework/static',
]

Apache 虚拟主机设置:

<VirtualHost 127.0.0.1:8081>
##ServerAdmin webmaster@dummy-host.example.com
WSGIScriptAlias / "D:/genesi5/Coding/www/django/wsgi_handler.wsgi"
DocumentRoot "D:/genesi5/Coding/www/django"
ServerName DjangoApp
ServerAlias DjangoApp
ErrorLog "logs/myapp/error.log"
CustomLog "logs/myapp/access.log" common
<Directory "D:/genesi5/Coding/www/django">
AllowOverride All
Require all Granted
</Directory>
</VirtualHost>

httpd.conf:

LoadModule wsgi_module "C:/Users/Genesi5/AppData/Local/Programs/Python/Python36-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win32.pyd"

<IfModule wsgi_module>
LoadFile "C:/Users/Genesi5/AppData/Local/Programs/Python/Python36-32/python36.dll"
WSGIPythonHome "C:/Users/Genesi5/AppData/Local/Programs/Python/Python36-32"
WSGIPassAuthorization On
</IfModule>

你能提出一个解决方案吗?

最佳答案

所以,我必须在虚拟主机设置中添加额外的别名,现在它有点起作用了:

<VirtualHost 127.0.0.1:8081>
##ServerAdmin webmaster@dummy-host.example.com
WSGIScriptAlias / "D:/genesi5/Coding/www/django/wsgi_handler.wsgi"
DocumentRoot "D:/genesi5/Coding/www/django"
ServerName DjangoApp
ServerAlias DjangoApp
ErrorLog "logs/myapp/error.log"
CustomLog "logs/myapp/access.log" common
Alias /static "C:/Users/Genesi5/AppData/Local/Programs/Python/Python36-32/Lib/site-packages/rest_framework/static"
<Directory "C:/Users/Genesi5/AppData/Local/Programs/Python/Python36-32/Lib/site-packages/rest_framework/static">
Require all Granted
</Directory>
<Directory "D:/genesi5/Coding/www/django">
AllowOverride All
Require all Granted
</Directory>
</VirtualHost>

关于python - 无法加载静态数据,Apache、Windows 上的 Django Rest_framework,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45281782/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com