2011-05-12 127 views
1

我使用apache + mod_wsgi + django。我遇到这种情况。我有一个浏览器中显示的网页,但没有应该在那里的CSS样式。这是我在setting.py和apache_django_wsgi.conf中的配置。django静态文件管理问题

设置潘岳:

import os.path 
import posixpath 

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__)) 
STATIC_ROOT = '' 
STATIC_URL = '/static/' 

STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static". 
# Always use forward slashes, even on Windows. 
# Don't forget to use absolute paths, not relative paths. 
'/Users/.../static', 
'/Users/.../static', 
'/Users/.../static', 
'/var/Project/static', 
) 

STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder', 
'django.contrib.staticfiles.finders.AppDirectoriesFinder', 
# 'django.contrib.staticfiles.finders.DefaultStorageFinder', 
) 

apache_django_wsgi:

Alias /static/ /var/Project/static/ 
<Directory /var/Project/static> 
Order allow,deny 
Options Indexes 
Allow from all 
IndexOptions FancyIndexing 
</Directory> 

所以我在哪里做错了?

,然后当我尝试“蟒蛇manage.py findstatic CSS/main.css的”返回我这样的错误消息:

Traceback (most recent call last): 
File "manage.py", line 35, in <module> 
execute_manager(settings) 
File "/usr/local/lib64/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager 
utility.execute() 
File "/usr/local/lib64/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute 
self.fetch_command(subcommand).run_from_argv(self.argv) 
File "/usr/local/lib64/python2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv 
self.execute(*args, **options.__dict__) 
File "/usr/local/lib64/python2.6/site-packages/django/core/management/base.py", line 219, in execute 
self.validate() 
File "/usr/local/lib64/python2.6/site-packages/django/core/management/base.py", line 249, in validate 
num_errors = get_validation_errors(s, app) 
File "/usr/local/lib64/python2.6/site-packages/django/core/management/validation.py", line 103, in get_validation_errors 
connection.validation.validate_field(e, opts, f) 
File "/usr/local/lib64/python2.6/site-packages/django/db/backends/mysql/validation.py", line 14, in validate_field 
db_version = self.connection.get_server_version() 
File "/usr/local/lib64/python2.6/site-packages/django/db/backends/mysql/base.py", line 338, in get_server_version 
self.cursor() 
File "/usr/local/lib64/python2.6/site-packages/django/db/backends/__init__.py", line 250, in cursor 
cursor = self.make_debug_cursor(self._cursor()) 
File "/usr/local/lib64/python2.6/site-packages/django/db/backends/mysql/base.py", line 322, in _cursor 
self.connection = Database.connect(**kwargs) 
File "/usr/lib64/python2.6/site-packages/MySQLdb/__init__.py", line 71, in Connect 
return Connection(*args, **kwargs) 
File "/usr/lib64/python2.6/site-packages/MySQLdb/connections.py", line 170, in __init__ 
super(Connection, self).__init__(*args, **kwargs2) 
_mysql_exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)") 

更新:Um..I认为的路径是正确的,因为当我检查了error_log,发现服务器可以找到css/js。它只是否认我的访问。该消息是这样的:

client denied by server configuration: /var/Project/static/js/jquery.min.js, referer: http://<server> 

因此,谁能教我怎么能解决这个问题?它与sql服务器有什么关系?

+0

您的mysql连接配置错误。首先测试你的mysql连接。 – 2011-05-12 05:23:18

+0

这不能是你的Apache配置,否则你真的把它塞满了。开始关闭对应的位置在哪里。包括正确的配置,不要编辑位。 – 2011-05-12 07:16:33

回答

0

您的回溯与静态文件无关。检查您的DATABASE_*DATABASES设置以符合您的环境。检查你的mysql守护进程是否正在运行(在Ubuntu中为ps aux | grep mysql)。在此回溯消失后,您必须执行python manage.py collectstatic,这将会将您的所有静态文件复制到Apache可以从中提供的一个位置。

+0

我以前收集过所有的静态文件。所有的css/js都在/var/.../static下 – Newbie 2011-05-12 04:53:45