gpt4 book ai didi

python - Django 找不到项目应用程序 - 无法导入 x_app

转载 作者:行者123 更新时间:2023-12-04 19:27:15 25 4
gpt4 key购买 nike

我正在将 django 项目从 Windows 环境迁移到 Ubuntu 环境。该项目存储在 git 中并克隆到 Ubuntu 环境中。我正在使用 virtualenv 来获得一个干净的状态(与 Windows 环境相同)。
我是否运行django-admin check或任何使用 python manage.py我收到以下错误:

Traceback (most recent call last):
File "/home/bitnami/djangoenv/lib/python3.8/site-packages/django/apps/config.py", line 244, in create
app_module = import_module(app_name)
File "/opt/bitnami/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'akita_app'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/bitnami/djangoenv/bin/django-admin", line 8, in <module>
sys.exit(execute_from_command_line())
File "/home/bitnami/djangoenv/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/home/bitnami/djangoenv/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
django.setup()
File "/home/bitnami/djangoenv/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/bitnami/djangoenv/lib/python3.8/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/home/bitnami/djangoenv/lib/python3.8/site-packages/django/apps/config.py", line 246, in create
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Cannot import 'akita_app'. Check that 'akitaapp.apps.AkitaAppConfig.name' is correct.
akita_appakitaapp (同样的事情)缺少的是 秋田app 文件夹。
编辑:我应该注意到我意识到我的 Windows 环境是 django 3.0.6 而我的 Ubuntu 环境是 3.2.9。
该项目在 Windows 环境中完美运行,所以我猜有些东西没有正确声明。我试过弄乱 PYTHONPATH无济于事。
我的项目结构如下所示。非常感谢可以提供的任何指导。
app/
├── akita_project
│   ├── akitaapp
│   │   ├── admin.py
│   │   ├── apps.py
│   │   ├── forms.py
│   │   ├── genpedigree.py
│   │   ├── __init__.py
│   │   ├── migrations
│   │   │   ├── 0001_initial.py
│   │   │   ├── 0002_auto_20200610_2116.py
│   │   │   ├── __init__.py
│   │   │   └── __pycache__
│   │   │   ├── 0001_initial.cpython-38.pyc
│   │   │   ├── 0002_auto_20200610_2116.cpython-38.pyc
│   │   │   └── __init__.cpython-38.pyc
│   │   ├── models.py
│   │   ├── __pycache__
│   │   │   ├── admin.cpython-38.pyc
│   │   │   ├── apps.cpython-38.pyc
│   │   │   ├── d_table.cpython-38.pyc
│   │   │   ├── forms.cpython-38.pyc
│   │   │   ├── genpedigree.cpython-38.pyc
│   │   │   ├── __init__.cpython-38.pyc
│   │   │   ├── models.cpython-38.pyc
│   │   │   ├── urls.cpython-38.pyc
│   │   │   └── views.cpython-38.pyc
│   │   ├── static
│   │   │   └── main
│   │   │   └── css
│   │   │   ├──redacted
│   │   ├── templates
│   │   │   └── main
│   │   │   ├──redacted
│   │   ├── testdigree.py
│   │   ├── tests.py
│   │   ├── urls.py
│   │   └── views.py
│   ├── akita_project
│   │   ├── asgi.py
│   │   ├── __init__.py
│   │   ├── migrations.me
│   │   ├── __pycache__
│   │   │   ├── __init__.cpython-38.pyc
│   │   │   ├── router.cpython-38.pyc
│   │   │   ├── settings.cpython-38.pyc
│   │   │   ├── urls.cpython-38.pyc
│   │   │   └── wsgi.cpython-38.pyc
│   │   ├── router.py
│   │   ├── settings.py
│   │   ├── urls.py
│   │   └── wsgi.py
│   ├── akita.sqlite3
│   ├── db.sqlite3
│   ├── desktop.ini
│   ├── __init__.py
│   ├── manage.py
│   └── output_data.csv
└── requirements.txt
urls.py
from django.contrib import admin
from django.urls import path, include


urlpatterns = [
path('tinymce/', include('tinymce.urls')),
path("", include('akitaapp.urls')),
path('admin/', admin.site.urls),

]
设置.py
import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'xxx'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True


ALLOWED_HOSTS = ['x']


# Application definition

INSTALLED_APPS = [
'materializecssform',
'tinymce',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'akitaapp',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'akita_project.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'akita_project.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases

DATABASE_ROUTERS = ['akita_project.router.AkitaDbRouter']

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
'akita_app': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'akita.sqlite3'),
}
}


# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_URL = '/static/'

TINYMCE_DEFAULT_CONFIG = {
'height': 360,
'width': 1120,
'cleanup_on_startup': True,
'custom_undo_redo_levels': 20,
'selector': 'textarea',
'theme': 'modern',
'plugins': '''
textcolor save link image media preview codesample contextmenu
table code lists fullscreen insertdatetime nonbreaking
contextmenu directionality searchreplace wordcount visualblocks
visualchars code fullscreen autolink lists charmap print hr
anchor pagebreak
''',
'toolbar1': '''
fullscreen preview bold italic underline | fontselect,
fontsizeselect | forecolor backcolor | alignleft alignright |
aligncenter alignjustify | indent outdent | bullist numlist table |
| link image media | codesample |
''',
'toolbar2': '''
visualblocks visualchars |
charmap hr pagebreak nonbreaking anchor | code |
''',
'contextmenu': 'formats | link image',
'menubar': True,
'statusbar': True,
}
应用程序.py
from django.apps import AppConfig


class AkitaAppConfig(AppConfig):
name = 'akita_app'

最佳答案

问题是你使用了不正确的名字 apps.py文件apps.py

from django.apps import AppConfig


class AkitaAppConfig(AppConfig):
name = 'akitaapp'

关于python - Django 找不到项目应用程序 - 无法导入 x_app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69892054/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com