静态文件未加载在Bluehost上托管的Django网站中

时间:2013-08-09 09:44:59

标签: python django static fastcgi bluehost

您可以在网站上看到它:http://www.workshopvenues.com 静态文件未正确加载。

我希望这个网址(例如)有效:http://www.workshopvenues.com/assets/ico/apple-touch-icon-144-precomposed.png 但它不是(因为你可以验证点击它)。

这就是我在 settings.py

中的内容
STATIC_ROOT = '/home6/ptlugorg/workshopvenues/workshopvenues/workshopvenues/assets/'

STATIC_URL = 'http://www.workshopvenues.com/assets/'

STATICFILES_DIRS = (
    '/home6/ptlugorg/workshopvenues/workshopvenues/workshopvenues/assets/',
)

路径是正确的,我仔细检查过它们:

ptlugorg@ptlug.org [~/workshopvenues/workshopvenues/workshopvenues/assets]# pwd
/home6/ptlugorg/workshopvenues/workshopvenues/workshopvenues/assets

如果有帮助,我正在使用fastcgi服务该网站。我按照http://simplyargh.blogspot.co.uk/2012/04/python-27-django-14-on-bluehost.html

中的说明进行操作

这些是我的配置文件。

的.htaccess

ptlugorg@ptlug.org [~/public_html/workshopvenues]# cat .htaccess 
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ workshopvenues.fcgi/$1 [QSA,L]

workshopvenues.fcgi

ptlugorg@ptlug.org [~/public_html/workshopvenues]# cat workshopvenues.fcgi 
#!/home6/ptlugorg/python27/bin/python27
import sys, os

# Add a custom Python path.
sys.path.insert(0, "/home6/ptlugorg/python27")
sys.path.insert(13, "/home6/ptlugorg/workshopvenues/workshopvenues")

os.environ['DJANGO_SETTINGS_MODULE'] = 'workshopvenues.settings'
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")

万一您想知道权限

ptlugorg@ptlug.org [~/workshopvenues/workshopvenues/workshopvenues]# ls -al
total 52
drwxr-xr-x  3 ptlugorg ptlugorg 4096 Aug  9 03:31 ./
drwxr-xr-x  4 ptlugorg ptlugorg 4096 Aug  9 02:52 ../
drwxr-xr-x 11 ptlugorg ptlugorg 4096 Aug  8 15:33 assets/
-rw-r--r--  1 ptlugorg ptlugorg    0 Aug  8 14:23 __init__.py
-rw-r--r--  1 ptlugorg ptlugorg  144 Aug  8 14:25 __init__.pyc
-rw-r--r--  1 ptlugorg ptlugorg  430 Aug  8 15:20 secrets.py
-rw-r--r--  1 ptlugorg ptlugorg  527 Aug  8 15:20 secrets.pyc
-rw-r--r--  1 ptlugorg ptlugorg 5779 Aug  9 03:31 settings.py
-rw-r--r--  1 ptlugorg ptlugorg 3399 Aug  9 03:31 settings.pyc
-rw-r--r--  1 ptlugorg ptlugorg  614 Aug  8 14:23 urls.py
-rw-r--r--  1 ptlugorg ptlugorg  467 Aug  8 15:23 urls.pyc
-rw-r--r--  1 ptlugorg ptlugorg 1150 Aug  8 14:23 wsgi.py
-rw-r--r--  1 ptlugorg ptlugorg 1058 Aug  8 15:21 wsgi.pyc

ptlugorg@ptlug.org [~/workshopvenues/workshopvenues/workshopvenues/assets]# ls -al
total 48
drwxr-xr-x 11 ptlugorg ptlugorg 4096 Aug  8 15:33 ./
drwxr-xr-x  3 ptlugorg ptlugorg 4096 Aug  9 03:31 ../
drwxr-xr-x  5 ptlugorg ptlugorg 4096 Aug  8 15:33 admin/
drwxr-xr-x  5 ptlugorg ptlugorg 4096 Aug  8 14:23 bootstrap/
drwxr-xr-x  2 ptlugorg ptlugorg 4096 Aug  8 14:23 css/
drwxr-xr-x  5 ptlugorg ptlugorg 4096 Aug  8 15:33 django_extensions/
drwxr-xr-x  2 ptlugorg ptlugorg 4096 Aug  8 14:23 font-awesome/
drwxr-xr-x  2 ptlugorg ptlugorg 4096 Aug  8 14:23 ico/
drwxr-xr-x  7 ptlugorg ptlugorg 4096 Aug  8 14:23 img/
drwxr-xr-x  2 ptlugorg ptlugorg 4096 Aug  8 14:23 js/
drwxr-xr-x  5 ptlugorg ptlugorg 4096 Aug  8 14:23 prettyPhoto/

一切似乎都是正确的,但它仍然没有按预期工作。你知道问题出在哪里吗?我可以做些什么测试来验证是否有问题?

感谢您的帮助!

3 个答案:

答案 0 :(得分:1)

感谢名为 mattmcc #django (Freenode IRC频道)的用户,我已经能够解决它。实际上这是 STATIC_ROOT 中的一个问题。它指向的是文本文件位置,而不是指向 DOCUMENT ROOT位置

正确的 settings.py 是这样的:

STATIC_ROOT = '/home6/ptlugorg/public_html/workshopvenues/assets/'

STATIC_URL = '/assets/'

STATICFILES_DIRS = (
    '/home6/ptlugorg/workshopvenues/workshopvenues/workshopvenues/assets/',
)

现在一切正常:)

答案 1 :(得分:0)

为了清楚起见:

  • STATIC_ROOT(所有应用中放置所有静态文件的目录)需要位于public_html/yoursite文件夹中才能正常工作。

答案 2 :(得分:0)

检查这个答案,Django: CSS Is not not working,似乎你必须运行python manage.py collectstatic并在你的urls.py中添加一些行