2017-01-15 68 views
0

這是我目前assets.py文件編譯。麻煩的建立目錄從Django的資產/ Webassets

無論如何,我將register('sass', sass)更改爲register('sass_all', sass)以避開錯誤。當我去編譯它正在尋找我的scripts目錄,我保持manage.py。在settings.py我補充一下:

ASSETS_ROOT = [ 
    'static', 
] 

剛剛有看在scripts/static不存在。

嘗試:

# This is already in settings.py 
STATICFILES_DIRS = [ 
    os.path.join(BASE_DIR, 'static'), 
] 

# Added new line 
ASSETS_ROOT = [ 
    STATICFILES_DIRS, 
] 

它會產生一個錯誤的夫婦:KeyError: 'directory'OSError: The environment has no "directory" configured,並AttributeError: 'list' object has no attribute 'startswith'。真的,這只是一個錯誤,directory沒有定義,我想。

通過environment documentation進行閱讀,這在我的技能水平上是含糊不清的。在assets.py中加入Environmentimport只是說Could not import in Environment。在Environment is not defined中添加Environment.directory('static')結果。只是directory('static')也導致directory is not definedenv = Environment()同樣的事情。試圖添加directory='/static'sass = Bundle(...),它只是說TypeError: got unexpected keyword argument 'directory'

無論如何,花了幾個小時,並再次卡住。文檔似乎指示directory設置應該在assets.py而不是settings.py,而ASSETS_ROOT應該在settings.py

再次提前致謝!從這個問題

~/portal-client 

project_dir 
    apps 
     account 
      templates 
       account 
        login.html 
      forms.py 
      urls.py 
      views.py 
     home 
      templates 
       home 
        home.html 
      urls.py 
      views.py 
     results 
    assets.py 
    settings.py 
    urls.py 
scripts 
    manage.py 
static 
    build 
     main.js 
     main.sass 
    css 
     app.css 
     main.css 
    js 
     app.js 
     main.js 
    media 
templates 
    base.html 
    footer.html 
    title.html 

繼續:Trouble adding Django-Assets/Webassets directory to look for assets.py files

回答

1

快速一點要注意:

# This is already in settings.py 
STATICFILES_DIRS = [ 
    os.path.join(BASE_DIR, 'static'), 
] 
# After this line STATICFILES_DIRS is `[ 'BASE_DIR/static' ]` 

# Added new line 
ASSETS_ROOT = [ 
    STATICFILES_DIRS, 
] 
# After this line, ASSETS_ROOT is `[ [ 'BASE_DIR/static' ] ]` 
# i.e., an array of arrays 
# I think you actually wanted: 
ASSETS_ROOT = STATICFILES_DIRS[0] 
# - or more explicitly - 
ASSETS_ROOT = os.path.normpath(os.path.join(BASE_DIR, 'static')) 

也就是說很多這樣的問題看起來像他們被相當非標準的Django結構造成的(即,您的manage.py位於scripts目錄中,而不是BASE_DIR)。

+0

再次感謝第三次關於這個問題!運行良好,我也有緩存破壞工作(不喜歡它保留每個版本,但至少它選擇最新的,但我會採取我現在可以得到的東西...雜亂是一個不同的日子的主題)。實際上深入到Django! – sockpuppet