2011-05-12 128 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