【问题标题】:django 1.10 list of installed appsdjango 1.10 已安装应用程序列表
【发布时间】:2017-05-13 19:59:35
【问题描述】:

所以我正在尝试这个:

import my_project.settings
DEVOPS_APPS = [ app for app in my_project.settings.INSTALLED_APPS if not "django" in app ]

有时当我刷新时,数据不显示。

其他时候,当我刷新时,数据会显示。

还有一些时候,当我刷新时,我会得到 INSTALLED_APPS 的完整列表

我的索引函数如下所示:

template = loader.get_template('dashboard/index.html')
      context = {
        'title': "Telematics DevOps Automation Team",
        'installed_apps': DEVOPS_APPS,
        'server': 'atllvasbap001i.hughestelematics.net',
        'charts': data['charts']
        }
return HttpResponse(template.render(context))

我做错了什么?

【问题讨论】:

  • 这两个sn-ps是什么关系?你在哪里使用 DEVOPS_APPS?
  • 糟糕。我在上下文字典中使用 DEVOPS_APPS。已编辑。

标签: python django django-templates django-views django-1.10


【解决方案1】:

使用设置时,django 建议导入django.conf.settings 而不是导入你的设置模块:

from django.conf import settings
[app for app in settings.INSTALLED_APPS if not 'django' in app]
# will output
# >>> [u'user_auth', u'payment', u'logistic', u'art', u'home', 
#      u'swipe', u'easy_thumbnails', u'crispy_forms', u'floppyforms',   
#      u'rest_framework', u'rest_framework.authtoken', 
#      u'adminsortable']

推荐阅读Using settings in Python code

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-17
    • 1970-01-01
    • 2011-09-04
    • 1970-01-01
    • 2017-05-25
    • 2011-06-04
    • 1970-01-01
    相关资源
    最近更新 更多