2017-01-15 43 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