带有Django模型的Sphinx没有声明显式的app lab

2024-04-25 22:58:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经花了无数个小时,但这还是卡住了。文件太少了。使用django1.10,尝试创建Sphinx文档,该文档出现了各种错误。最后我被困在这里了。我在我的主应用程序kyc_connect中创建了一个示例模型,如下所示。在

在模型.py在

from django.db import models
class example(models.Model):        
    filed1 = models.DateTimeField(auto_now=True)

    # class Meta:
    #     app_label = 'kyc_connect'

运行make_html会产生以下错误。在

RuntimeError: Model class kyc_connect.models.example doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

在配置文件导入设置

^{pr2}$

当我包括当前注释掉的Meta类时,这个错误就消失了。 但是如果我包含一个带有ForeignKey和import from django.contrib.auth.models import User的模型,就会出现错误RuntimeError: Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

已安装的应用程序

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework_swagger',
    'rest_framework',
    'rest_framework.authtoken',
    'kyc_connect',
    'kyc_connect_data_models',
    'kyc_rest_services.kyc_connect_accounts',
    'kyc_rest_services.kyc_connect_documents',
    'kyc_rest_services.kyc_connect_transaction_manager',
    'tasks',
    'elasticstack',
    'corsheaders',
    'haystack'
]

项目结构

kyc_connect:
  -config
  -docs
  -kyc_connect
    -models.py
    .
    .
  -kyc_connect_data_models
  -kyc_core
  -kyc_rest_services
    -kyc_connect_accounts
    -kyc_connect_transaction_manager
    .
    .
  .
  .

我已经在那里了。但django似乎不明白。我不想声明元类。出什么问题了。任何帮助都会很好。在


Tags: djangoin模型importanrestappmodel
3条回答

对于其他仍在努力解决这个问题的人来说,这可能有助于:

请注意:

.. automodule:: appName.models

而不是像:

^{pr2}$

如果您喜欢我,出于某些原因,可以附加在django根目录的父文件夹中的docs目录。在

注意:为了正常工作,我的视图和任务必须设置为:

.. automodule:: ProjectName.appName.tasks
.. automodule:: ProjectName.appName.views

希望能节省时间。在

我的项目也有同样的错误。我通过改变我在所有应用程序文件中导入模型的方式来解决这个问题。例如在中注册模型管理员py改变

from project.app.models import YourModel

到。。

^{pr2}$

我在我的项目中遇到了同样的问题,最后通过删除我的配置文件文件和运行

make clean
make html

在我的文档目录中。在

相关问题 更多 >