【问题标题】:Django debug-toolbar - Can't make it work (ImproperlyConfigured: The STATICFILES_DIRS ...)Django 调试工具栏 - 无法正常工作(配置不当:STATICFILES_DIRS ...)
【发布时间】:2014-03-19 20:35:28
【问题描述】:

错误(运行 django runserver 命令时):

配置不当:STATICFILES_DIRS 设置不应包含 STATIC_ROOT 设置

我并没有真正使用 django static(这主要是和 api 服务器),我只希望 django debug 来调试和explain 我的 sql 查询。所以我所拥有的是:

STATIC_DIRECTORY = '/'
    MEDIA_DIRECTORY = '/media/'
    STATIC_URL = S3_URL + STATIC_DIRECTORY
    MEDIA_URL = S3_URL + MEDIA_DIRECTORY

    STATICFILES_STORAGE = 'server.s3utils.StaticRootS3BotoStorage'
    DEFAULT_FILE_STORAGE = 'server.s3utils.MediaRootS3BotoStorage'


STATIC_ROOT = 'staticfiles'

    STATICFILES_DIRS = (
        abs_path('staticfiles'),
        # ABS_PATH('/static/'),  #D either
    )oesn't work either
    )

编辑:如果我只是删除 STATICFILES_DIRS,错误会发生变化:

TypeError at /admin/ 调用元类库时出错 function() 参数 1 必须是代码,而不是 str 请求方法:GET 请求 URL:http://localhost:8000/admin/ Django 版本:1.6.2 异常类型:TypeError 异常值:调用时出错 元类基础 function() 参数 1 必须是代码,而不是 str

我也尝试了作为建议添加的答案之一

 if settings.DEBUG:
     import debug_toolbar
     urlpatterns += patterns('',
         url(r'^__debug__/', include(debug_toolbar.urls)),
     )

没用..

我想我遗漏了一些非常简单(但很烦人)的东西,我很乐意为此提供帮助。

【问题讨论】:

标签: python django boto


【解决方案1】:

我在使用 lambda 创建自定义存储时遇到了同样的错误:

StaticRootS3BotoStorage = lambda: S3Boto3Storage(bucket_name='example-name') 

将其更改为类解决了问题:

class StaticRootS3BotoStorage(S3Boto3Storage):
    bucket_name='example-name'

【讨论】:

    【解决方案2】:

    使用 S3BotoStorage 时 Django 调试工具栏阻塞。我主要想要 SQL 日志记录,因此将此代码添加到 settings.py 以禁用 StaticFilesPanel 对我来说是一种解决方法:

    DEBUG_TOOLBAR_PANELS = [
     'debug_toolbar.panels.versions.VersionsPanel',
     'debug_toolbar.panels.timer.TimerPanel',
     'debug_toolbar.panels.settings.SettingsPanel',
     'debug_toolbar.panels.headers.HeadersPanel',
     'debug_toolbar.panels.request.RequestPanel',
     'debug_toolbar.panels.sql.SQLPanel',
     # 'debug_toolbar.panels.staticfiles.StaticFilesPanel',                                                                                                                                    
     'debug_toolbar.panels.templates.TemplatesPanel',
     'debug_toolbar.panels.cache.CachePanel',
     'debug_toolbar.panels.signals.SignalsPanel',
     'debug_toolbar.panels.logging.LoggingPanel',
     'debug_toolbar.panels.redirects.RedirectsPanel',
    ]
    

    【讨论】:

      【解决方案3】:

      这个django-debug-toolbar explicit-setup 说了一些关于:

      from django.conf import settings
      from django.conf.urls import include, patterns, url
      
      if settings.DEBUG:
          import debug_toolbar
          urlpatterns += patterns('',
              url(r'^__debug__/', include(debug_toolbar.urls)),
          )
      

      你试过了吗?

      【讨论】:

        猜你喜欢
        • 2013-02-10
        • 1970-01-01
        • 2016-12-11
        • 1970-01-01
        • 1970-01-01
        • 2016-06-26
        • 1970-01-01
        • 2017-08-13
        • 2013-05-03
        相关资源
        最近更新 更多