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

yipeiwu_com5年前Python基础

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

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

import os
PROJECT_ROOT = os.path.dirname(__file__)

DEBUG = True

STATIC_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
   ServerAdmin fake@mydjangosite.com

   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利用dir函数查看类中所有成员函数示例代码

python利用dir函数查看类中所有成员函数示例代码

前言 如果一个类是别人编写的,又没有帮助文档,怎么样来查看所有成员函数呢?本文详细给大家介绍了关于python用dir函数查看类中所有成员函数的相关内容,下面话不多说了,来一起看看详细的...

python操作xml文件示例

复制代码 代码如下:def get_seed_data(filename):dom = minidom.parse(filename)root = dom.documentElement...

Python数据类型详解(四)字典:dict

一.基本数据类型   整数:int   字符串:str(注:\t等于一个tab键)   布尔值: bool   列表:list   列表用[]   元祖:tuple   元祖用()...

Python中用PIL库批量给图片加上序号的教程

Python中用PIL库批量给图片加上序号的教程

女友让我给她论文的图片上加上字母序号,本来觉得是个很简单的事情,但那个白底黑字的圆圈序号却难住了我, 试了几个常用的软件,都不行。 后来用 PS + 动作,倒是能搞出来,不过也不容易,正...

使用Python的Django框架结合jQuery实现AJAX购物车页面

使用Python的Django框架结合jQuery实现AJAX购物车页面

Django中集成jquery 首先,静态的资源通常放入static文件夹中: static/ css/ djquery.css samples/...