在settings.py中,如果我指定 STATIC_URL = 'http://68.164.125.221/'
,则客户端可以访问我的网页 . 但是,没有加载CSS和其他静态文件 .
另一方面,如果我指定 STATIC_URL = '/'
,则访问我的应用程序的主页会产生此错误 .
Page not found (404)
Request Method: GET
Request URL: http://68.164.125.221/
Directory indexes are not allowed here.
You're seeing this error because you have DEBUG = True in your Django settings file.
有趣的是,我的静态文件现在加载(例如http://68.164.125.221/main.css加载)尽管我的应用程序的主页显示此错误 .
为什么更改我的“STATIC_URL”设置会切换我的主页加载还是我的静态文件加载?我正在使用staticfiles应用程序 .
1 回答
你可能想要
STATIC_URL = '/static/'
[1];当你将它设置为/
时,Django正在尝试将/blah/
作为静态文件提供,而不是将其推送到您的Django应用程序 .您获得的实际错误
Directory indexes are not allowed here.
指的是未列出静态文件夹的事实 - 您必须访问特定文件才能提供该文件 .[1]或/ media /,或/ files /,或其他......只是不是'/' .