2014-06-16 22 views
1

我正在運行django-nvd3演示項目,看到沒有顯示餅圖。 我看到下面的請求失敗nvd3與演示項目中的'Get'請求失敗?

GET http://localhost:8000/static/nvd3/src/nv.d3.css 
GET http://localhost:8000/static/nvd3/src/nv.d3.css show_graph:3 
GET http://localhost:8000/static/nvd3/nv.d3.min.js show_graph:5 
GET http://localhost:8000/static/d3/d3.min.js 

我已經安裝了Python-nvd3及其所有的依賴。這裏是我對配置文件的配置

BASE_DIR = dirname(dirname(__file__)) 

# Quick-start development settings - unsuitable for production 
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/ 

# Absolute path to the directory static files should be collected to. 
# Don't put anything in this directory yourself; store your static files 
# in apps' "static/" subdirectories and in STATICFILES_DIRS. 
# Example: "/home/media/media.lawrence.com/static/" 
STATIC_ROOT = join(BASE_DIR, 'static') 

BOWER_COMPONENTS_ROOT = join(BASE_DIR, 'components') 

# URL prefix for static files. 
# Example: "http://media.lawrence.com/static/" 
STATIC_URL = '/static/' 

# Additional locations of static files 
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. 
) 

# List of finder classes that know how to find static files in 
# various locations. 
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder', 
    'django.contrib.staticfiles.finders.AppDirectoriesFinder', 
    'compressor.finders.CompressorFinder', 
    'djangobower.finders.BowerFinder', 
) 

BOWER_INSTALLED_APPS = ( 
    'jquery', 
    'underscore', 
    'd3#3.3.6', 
    'nvd3#1.1.12-beta', 
) 

我在想什麼?

+0

你解決了嗎?我得到相同的錯誤 – doniyor

回答

0

在生產環境中,您必須使用您選擇的網絡服務器來提供靜態文件。您的設置中的評論意味着您正在運行開發服務器。在這種情況下,將'django.contrib.staticfiles'添加到已安裝的應用程序就足夠了。當DEBUG = True時,staticfiles應用程序將自動提供在STATICFILES_DIRS中找到的靜態文件或由各種STATICFILES_FINDERS使用python傳輸響應。

不要在生產環境中使用它,因爲它效率低下,可能不安全。

相反,使用您的網絡服務器(Apache,IIS,gunicorn等)來提供靜態文件。管理命令collectstatic將收集所有靜態文件到中心位置(您的STATIC_ROOT)。然後設置您的網絡服務器以從該位置提供靜態文件。

有關如何執行此操作的更多信息,請參閱'Deploying static files'以及您的網絡服務器的文檔。

+0

感謝您的幫助,但我認爲問題是與BOWER的設置,因爲理想情況下,'djangobower.finders.BowerFinder應該已經自動找到所有需要的nvd3靜態文件工作? – user1524625

+0

@ user1524625你是否在你的設置中指定了'BOWER_INSTALLED_APPS',並運行'./manage.py bower install'?此外,你_are_服務你的靜態文件,如我貼,對吧?請求失敗,404是什麼? – knbk

+1

如果你看到上面的'STATICFILES_FINDERS',它有'涼亭設置'。 這是我的已安裝的應用的設置 BOWER_INSTALLED_APPS =( '的jquery', '下劃線', 'D3#3.3.6', 'nvd3#1.1.12-β', ) – user1524625