Django: RuntimeError: Model class test_django.apps.app1.models.xxx doesn’t declare an explicit app_label and isn’t in an application in INSTALLED_APPS.Django: RuntimeError: Model class test_django.apps.app1.models.xxx doesn’t declare an explicit app_label and isn’t in an application in INSTALLED_APPS.Django: RuntimeError: Model class test_django.apps.app1.models.xxx doesn’t declare an explicit app_label and isn’t in an application in INSTALLED_APPS.Django: RuntimeError: Model class test_django.apps.app1.models.xxx doesn’t declare an explicit app_label and isn’t in an application in INSTALLED_APPS.
  • 首页
  • 博客
  • 书签
  • 文件
  • 分析
  • 登录

Django: RuntimeError: Model class test_django.apps.app1.models.xxx doesn’t declare an explicit app_label and isn’t in an application in INSTALLED_APPS.

发表 admin at 2022年7月31日
类别
  • Django
标签

1.Django项目错误提示:

RuntimeError: Model class xxx.apps.users.models.User doesn’t declare an explicit app_label and isn’t in an application in INSTALLED_APPS.

2. 项目结构:

django_project
    ├── LICENSE
    ├── main.py
    └── test_django
        ├── manage.py
        └── test_django
            ├── apps
            │   ├── app1
            │   │   ├── admin.py
            │   │   ├── apps.py
            │   │   ├── __init__.py
            │   │   ├── models.py
            │   │   ├── tests.py
            │   │   ├── urls.py
            │   │   └── views.py
            │   └── app2
            │       ├── admin.py
            │       ├── apps.py
            │       ├── __init__.py
            │       ├── models.py
            │       ├── tests.py
            │       ├── urls.py
            │       └── views.py
            ├── asgi.py
            ├── __init__.py
            ├── settings
            │   ├── dev.py
            │   └── prod.py
            ├── urls.py
            └── wsgi.py

2.解决

1. app内,使用相对路径引用Models模块:

# 在apps.app1.urls.py中导入apps.app1.views.py
from . import views

# 在apps.app1.views.py中导入apps.app1.models.py中的xxx
from .models import xxx

2. 不同app之间,使用以apps为根目录的绝对路径:

# 在apps.app2.views.py中导入apps.app1.models.py中的xxx
from app1.models import xxx

3. 其它参考

https://stackoverflow.com/questions/35388637/runtimeerror-model-class-django-contrib-sites-models-site-doesnt-declare-an-ex

发表回复 取消回复

要发表评论,您必须先登录。

类别

  • Cat
  • Python
  • Django
  • Database
  • Html/CSS
  • JavaScript
  • Vue
  • RegExp
  • Maths/AI
  • PHP/Wordpress
  • Practice
  • Linux
  • Windows
  • Android
  • NAS
  • Software
  • Hardware
  • Network
  • SEO
  • English
  • Games
  • Recipes
  • General
  • Memorandum
  • Essays
  • 未分类

归档

©2015-2023 艾丽卡 Blog support@alaica.com
      ajax-loader