LookupError:没有安装带标签'app'的应用程序(Django 1.11 / Python 2.7 / xadmin)

时间:2018-02-20 15:47:43

标签: python django

不能为我的生活找出问题所在。求救!

我正在尝试通过添加图表来扩展管理视图(使用xadmin应用程序)

问题开始出现,增加了:

管理

from xadmin import views    
from .models import DGISummary
...

@xadmin.sites.register(views.website.IndexView)
class MainDashboard(object):
widgets = [
    [
        {
            "type": "chart", 
            "model": "dgisummary",
            "chart": "reg_members",
            "params": 
            {
                "_p_date__gte": "2017-01-01", 
                "p": 1,
                "_p_date__lt": "2017-12-01"
            }
        },
    ],
]

模型

@python_2_unicode_compatible
class DGISummary(models.Model):
    quarter = models.CharField(max_length=2,)
    reg_members = models.IntegerField()
    sub_received = models.IntegerField()
    ...

    class Meta:
        verbose_name = u"Summary"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.quarter

追溯

System check identified no issues (0 silenced).
February 20, 2018 - 15:38:35
Django version 1.11.10, using settings 'csa_portal.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
ERROR:root:No installed app with label 'app'.
Traceback (most recent call last):
  File "C:/../apps\xadmin\views\dashboard.py", line 563, in get_widgets
    ws.append(self.get_widget(widget))
  File "C:/../apps\xadmin\views\base.py", line 78, in method
    return filter_chain(filters, len(filters) - 1, _inner_method, *args, **kwargs)
  File "C:/../apps\xadmin\views\base.py", line 47, in filter_chain
    return func()
  File "C:/../apps\xadmin\views\base.py", line 72, in _inner_method
    return func(self, *args, **kwargs)
  File "C:/../apps\xadmin\views\dashboard.py", line 517, in get_widget
    wid_instance = widget_with_perm(self, data or widget.get_value())
  File "C:/../apps\xadmin\views\dashboard.py", line 325, in __init__
    super(ModelBaseWidget, self).__init__(dashboard, data)
  File "C:/../apps\xadmin\views\dashboard.py", line 200, in __init__
    if not self.is_valid():
  File "C:\Python27\lib\site-packages\django\forms\forms.py", line 183, in is_valid
    return self.is_bound and not self.errors
  File "C:\Python27\lib\site-packages\django\forms\forms.py", line 175, in errors
    self.full_clean()
  File "C:\Python27\lib\site-packages\django\forms\forms.py", line 384, in full_clean
    self._clean_fields()
  File "C:\Python27\lib\site-packages\django\forms\forms.py", line 402, in _clean_fields
    value = field.clean(value)
  File "C:\Python27\lib\site-packages\django\forms\fields.py", line 160, in clean
    value = self.to_python(value)
  File "C:/../apps\xadmin\views\dashboard.py", line 301, in to_python
    return apps.get_model(app_label, model_name)
  File "C:\Python27\lib\site-packages\django\apps\registry.py", line 200, in get_model
    app_config = self.get_app_config(app_label)
  File "C:\Python27\lib\site-packages\django\apps\registry.py", line 156, in get_app_config
    raise LookupError(message)
LookupError: No installed app with label 'app'.

奇怪的是,有一个应用程序的演示,我基于我的代码。这包括以下行:

class MainDashboard(object):
    widgets = [
        [
            {
            "type": "html", 
            "title": "Test Widget",
            "content": "<h3> Welcome to Xadmin! </h3><p>Join Online Group: <br/>QQ Qun : 282936295</p>"
            },
            {
                "type": "chart", 
                "model": "app.accessrecord", 
                "chart": "user_count",
                 "params": 
                    {
                    "_p_date__gte": "2013-01-08", 
                    "p": 1, 
                    "_p_date__lt": "2013-01-29"
                    }
             },

不确定这里发生了什么。任何指针都会受到赞赏。

修改

根据要求,已安装的应用:

INSTALLED_APPS = [
    'admin_bootstrap',
    'survey',
    'xadmin',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'dashing',
    'formtools',
    'crispy_forms',
    'reversion',
]

2 个答案:

答案 0 :(得分:2)

您需要转到settings.py文件并将xadmin添加到INSTALLED_APPS列表。

请参阅此处的文档:https://docs.djangoproject.com/en/2.0/ref/applications/#for-application-users

答案 1 :(得分:0)

您必须已运行demo_app,因此db.sqlite3已存储了MainDashboard类中的“小部件”。

class MainDashboard(object):
widgets = [
    [
        {
        "type": "html", 
        "title": "Test Widget",
        "content": "<h3> Welcome to Xadmin! </h3><p>Join Online Group: <br/>QQ Qun : 282936295</p>"
        },
        {
            "type": "chart", 
            "model": "app.accessrecord", 
            "chart": "user_count",
             "params": 
                {
                "_p_date__gte": "2013-01-08", 
                "p": 1, 
                "_p_date__lt": "2013-01-29"
                }
         },

在此小部件中,模型使用“ app.accessrecord”,
对我来说,我只清空此表的“ xadmin_userwidget”并注释“ widgets”,这解决了我的问题