gpt4 book ai didi

python - Django项目重组: Can't import app

转载 作者:行者123 更新时间:2023-12-02 20:47:44 25 4
gpt4 key购买 nike

我正在尝试重组我的项目,以符合最新的《Two Scoops of Django》一书(针对 Django 1.11)中的建议。

完成重组后,我的应用无法导入。

secureDash_project
├── README.rst
├── config
│   ├── __init__.py
│   ├── __pycache__
│   ├── db.sqlite3
│   ├── settings
│   │   ├── __init__.py
│   │   ├── __pycache__
│   │   └── settings.py
│   ├── urls.py
│   └── wsgi.py
├── db.sqlite3
├── manage.py
├── requirements.txt
└── secureDash
├── __init__.py
├── __pycache__
├── dash
│   ├── __init__.py
│   ├── __pycache__
│   ├── admin.py
│   ├── apps.py
│   ├── forms.py
│   ├── migrations
│   │   └── __init__.py
│   ├── models.py
│   ├── tests.py
│   ├── urls.py
│   └── views.py
└── templates
└── dash

settings.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.dirname(os.path.abspath(__file__))))
ENV_PATH = os.path.abspath(os.path.dirname(__file__))

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

# Application definition

INSTALLED_APPS = [
'secureDash.dash.apps.DashConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# 'django_static_jquery',
# 'bootstrap3',
] ...

运行时

python3 manage.py runserver --settings=config.settings.settings

我得到:

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x1076b0d08>
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 113, in inner_run
autoreload.raise_last_exception()
File "/usr/local/lib/python3.5/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/usr/local/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/usr/local/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.5/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python3.5/site-packages/django/apps/config.py", line 142, in create
app_module = import_module(app_name)
File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named 'dash'

secureDash.dash.apps.DashConfig:

from django.apps import AppConfig


class DashConfig(AppConfig):
name = 'dash'

最佳答案

INSTALLED_APPS 中的 secureDash.dash.apps.DashConfig 替换为 secureDash.dash 应该可以修复该问题。

关于python - Django项目重组: Can't import app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43621259/

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