2013-02-09 139 views
0

我是新來的Django和管理區域的CSS不呈現。首先,我創建了一個管理模塊加載的應用程序,這就是我所做的:渲染管理員靜態文件 - DJANGO

通過將調試模式更改爲false並添加數據庫憑證來配置setting.py。然後:

manage.py syncdb 

Creating tables ... 
Installing custom SQL ... 
Installing indexes ... 
Installed 0 object(s) from 0 fixture(s) 

-

manage.py collectstatic 

You have requested to collect static files at the destination 
location as specified in your settings. 

This will overwrite existing files! 
Are you sure you want to do this? 

Type 'yes' to continue, or 'no' to cancel: yes 
Copying '/Library/Python/2.7/site-packages/django/contrib/admin/static/admin/css/base.css' 
Copying '/Library/Python/2.7/site-packages/django/contrib/admin/static/admin/css/changelists.css' 
Copying '/Library/Python/2.7/site-packages/django/contrib/admin/static/admin/css/dashboard.css' 
Copying '/Library/Python/2.7/site-packages/django/contrib/admin/static/admin/css/forms.css' 
Copying '/Library/Python/2.7/site-packages/django/contrib/admin/static/admin/css/ie.css' 
Copying '/Library/Python/2.7/site-packages/django/contrib/admin/static/admin/css/login.css' 
Copying '/Library/Python/2.7/site-packages/django/contrib/admin/static/admin/css/rtl.css' 

(...)

我所得到的,當我開始

Development server is running at http://127.0.0.1:8000/ 
Quit the server with CONTROL-C. 
[09/Feb/2013 13:57:53] "GET /admin/ HTTP/1.1" 200 3270 
Traceback (most recent call last): 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run 
    File "/Library/Python/2.7/site-packages/django/core/handlers/wsgi.py", line 241, in __call__ 
Traceback (most recent call last): 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run 
    File "/Library/Python/2.7/site-packages/django/core/handlers/wsgi.py", line 241, in __call__ 
    response = self.get_response(request) 
    response = self.get_response(request) 
    File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 153, in get_response 
    File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 153, in get_response 
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info()) 
    File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 228, in handle_uncaught_exception 
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info()) 
    File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 228, in handle_uncaught_exception 
    return callback(request, **param_dict) 

主頁上提供了一個「服務器錯誤服務器發生了,請聯繫管理員。「,我可以訪問site.com/admin/,但沒有css。該項目文件夾看起來是這樣的:

--project 
----manage.py 
----admin 
-------css 
-------img 
-------js 
----project 
-------setting.py 
-------urls.py 
-------wsgi.py 
-------__init__.py 

回答

1

首先,如果你正在運行的開發服務器(帶python manage.py runserver),那麼你應該有你的DEBUG設置爲true。此外,它看起來像您的STATIC_ROOT設置尚未設置(或設置爲您的項目的根目錄 - 這不是你想要在生產中運行應用程序時想要的)。

在您的settings.py文件中,您需要確保您有django.contrib.staticfiles包含在INSTALLED_APPS設置中。然後確保你已經定義了STATIC_URL(我認爲它應該默認爲/static/)。假設你在django的開發服務器上使用django 1.4,那麼一切都應該正常運行,無需運行collectstatic

查看serving static files上的文檔。值得注意的是,當您在生產服務器上執行服務時,提供靜態文件的過程是不同的。