2014-03-06 49 views
0

我使用django管理基本的CRUD。我的管理模板很容易加載,即使加載了css文件,但它根本沒有任何效果。Django管理css文件沒有呈現

我試圖收集靜態文件,如下

Manage.py collectstaic 

它顯示了以下錯誤

Traceback (most recent call last): 
    File "C:\Python27\Lib\site-packages\django\bin\hello\manage.py", line 10, in 
module> 
    execute_from_command_line(sys.argv) 
    File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 
399, in execute_from_command_line 
    utility.execute() 
    File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 
392, in execute 
    self.fetch_command(subcommand).run_from_argv(self.argv) 
    File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 
272, in fetch_command 
    klass = load_command_class(app_name, subcommand) 
    File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 
76, in load_command_class 
    return module.Command() 
    File "C:\Python27\lib\site-packages\django\contrib\staticfiles\management\com 
ands\collectstatic.py", line 58, in __init__ 
    self.storage.path('') 
    File "C:\Python27\lib\site-packages\django\contrib\staticfiles\storage.py", l 
ne 46, in path 
    raise ImproperlyConfigured("You're using the staticfiles app " 
django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app w 
thout having set the STATIC_ROOT setting to a filesystem path. 

如何解決UT?

+0

集STATIC_ROOT settings.py中? django必須知道你想在哪裏收集靜態文件 – simar

回答

0

包括你的STATIC_ROOT,例如。

STATIC_ROOT = 'staticfiles' 
STATIC_URL = '/static/' 
STATICFILES_DIRS = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'static') 

然後將其包含在urls.py文件中相應的url例如。

urlpatterns = patterns('',) +static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) 

記得把

from django.conf import settings 
from django.conf.urls.static import static 
urls.py

然後

在你的終端類型python manage.py collectstatic不collectstaic