我已经尝试过所有提供的解决方案,但没有运气。 我添加了静电'文件夹到根目录。 这是我用CentOS 6转移到Godaddy的VPS的旧django应用程序。 服务器上还有另一个非python网站。
/etc/httpd/conf/httpd.conf
<VirtualHost *:80>
ServerName familyfn.com
ServerAlias www.familyfn.com
# Note: Whether or not django can write to a directory is controlled by filesys$
# Apache's internal directory auth has to give the vhost access to the wsgi.py $
<Directory /home/familysu/public_html/wsgi>
Options None
AllowOverride None
Order Deny,Allow
Allow from all
</Directory>
# Apache's internal directory auth has to give the vhost access to directories $
<Directory /home/familysu/public_html/code/mediafiles>
Options None
AllowOverride None
Order Deny,Allow
Allow from all
</Directory>
<Directory /home/familysu/public_html/code/staticfiles>
Options None
AllowOverride None
Order Deny,Allow
Allow from all
</Directory>
<Directory /home/familysu/public_html/code/breakdown/static>
Options None
AllowOverride None
Order Deny,Allow
Allow from all
</Directory>
# Use the following to restrict access during review. You'll need to generate t$
#<Location "/">
# AuthName "familysu Review"
# AuthType Basic
# Require valid-user
# AuthUserFile /home/familysu/public_html/reviewusers.htpasswd
#</Location>
# mod_wsgi works with the Alias directive such that aliased files and directori$
Alias /media/ /home/familysu/public_html/code/mediafiles/
Alias /static/ /home/familysu/public_html/code/staticfiles/
Alias /robots.txt /home/familysu/public_html/code/breakdown/static/robots.txt
Alias /favicon.ico /home/familysu/public_html/code/breakdown/static/favicon.ico
WSGIDaemonProcess www.familyfn.com processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup www.familyfn.com
# Note: wsgi.py is in its own folder so the above directory permissions will ap$
WSGIScriptAlias / /home/familysu/public_html/wsgi/wsgi.py
LogLevel warn
ErrorLog /home/familysu/public_html/logs/error.log
CustomLog /home/familysu/public_html/logs/access.log combined
</VirtualHost>
setting.py:
STATIC_ROOT = os.path.join(TOP_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(TOP_DIR, 'breakdown', 'static'),
]
django版本1.1.4; python版本2.6
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.humanize',
'django.contrib.sessions',
'django.contrib.sites',
'staticfiles',
'sky_redirects',
'cms',
'cms.plugins.text',
'cms.plugins.picture',
'cms.plugins.link',
'cms.plugins.file',
'cms.plugins.snippet',
'cms.plugins.googlemap',
'mptt',
'publisher',
'filebrowser',
'mainsite.articles',
'mainsite.zone_report',
'mainsite.pressroom',
'mainsite.downloads',
)
我已经检查了这个:
python manage.py findstatic --verbosity 2 css/styles.css
它找到了正确的路径:
Found 'css/styles.css' here:
/home/familysu/public_html/code/breakdown/static/css/styles.css
答案 0 :(得分:0)
我很难记住静态文件在1.1中是如何工作的。但是,Apache配置中的这一行似乎是错误的:
Alias /static/ /home/familysu/public_html/
应该是这样的:
STATIC_ROOT
我认为Django 1.1没有STATIC_URL
和STATICFILES_DIRS
以及{{1}}。