0

正如您在网站上看到的那样:http ://www.workshopvenues.com /assets/* 下 的静态文件未正确加载。

我希望这个网址(例如)有效: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/

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

谢谢你的帮助!

4

3 回答 3

1

感谢#django(Freenode IRC 频道)中名为mattmcc的好心用户,我已经能够修复它。实际上这是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/',
)

现在一切正常:)

于 2013-08-09T10:58:30.220 回答
0

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

于 2014-01-06T09:55:37.057 回答
0

为清楚起见:

  • STATIC_ROOT(放置所有应用程序中的所有静态文件的目录)需要在您的public_html/yoursite文件夹中才能工作。
于 2014-01-02T20:44:03.290 回答