• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

python django 访问静态文件出现404或500错误

python 搞代码 4年前 (2022-01-09) 18次浏览 已收录 0个评论

django static文件夹下面的内容方法不了 出现404 500错误

需要查看自己的settings文件确保有一下内容

import osPROJECT_ROOT = os.path.dirname(__file__)DEBUG = TrueSTATIC_URL = '/static/'STATICFILES_DIRS = (  os.path.join(PROJECT_ROOT, 'static'),)STATICFILES_FINDERS = (  'django.contrib.staticfiles.finders.FileSystemFinder',  'django.contrib.staticfiles.finders.AppDirectoriesFinder',)

如果项目是使用eclipse启动的django工程 settings文件中的DEBUG 值要等于True 静态文件才能访问?这一点不太明白

如果需要部署到web站点上需要在apache中配置静态文件映射

<VirtualHost *:80>   ServerName www.mydjangosite.com   ServerAlias mydjangosite.com   <strong style="color:transparent">本文来源gaodai#ma#com搞@@代~&码*网/</strong>ServerAdmin [email protected]   DocumentRoot /path/to/mydjangosite   <Directory /path/to/mydjangosite>       Options FollowSymLinks       AllowOverride None       Order allow,deny       allow from all   </Directory>   Alias /static/ /path/to/mydjangosite/static/   <Directory /path/to/mydjangosite/static>       Order allow,deny       allow from all   </Directory>   # The following installs the Django WSGI app   WSGIDaemonProcess www.mydjangosite.com processes=2 threads=15 display-name=%{GROUP}   WSGIProcessGroup www.mydjangosite.com   WSGIScriptAlias / /path/to/mydjangosite/wsgi.py</VirtualHost>

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

更多python django 访问静态文件出现404或500错误相关文章请关注搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:python django 访问静态文件出现404或500错误
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址