【发布时间】:2020-05-16 08:30:32
【问题描述】:
我想知道是否有人可以帮助我。我正在寻找重组一个新的 django 项目,以代表以下内容:
-repository/
-config/
-asgi.py
-settings.py
-urls.py
-wsgi.py
-__init__.py
-project root/
-app_1/
-admin.py
-apps.py
-models.py
-tests.py
-urls.py
-views.py
-__init__.py
-app_2/
-...
-app_3/
-...
-migrations/
-__init__.py
-static/
-templates/
-docs/
-manage.py
到目前为止,我已尝试通过将以下行附加到 settings.py 文件来实现这一点:
# This is the <repository root>
BASE_DIR = Path(__file__).resolve().parent.parent
# This is the <project repository>
PROJECT_ROOT = BASE_DIR / 'project'
MEDIA_ROOT = PROJECT_ROOT / 'media'
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_ROOT = PROJECT_ROOT / 'static_root'
STATIC_URL = PROJECT_ROOT / 'static'
ROOT_URLCONF = 'config.urls'
Templates = [{ ...
'DIRS': [PROJECT_ROOT / 'templates'],
... }]
在已安装的应用程序中,我必须指定“.app1”而不是传统上的“app1”。我修改了manage.py、wsgi.py、asgi.py等文件指向设置文件。
但是...
当我尝试使用以下命令在配置根 urlconf 中包含()应用特定的 urlconf 时:
from django.contrib import admin
from django.urls import path, include
import project.app1
urlpatterns = [
path('admin/', admin.site.urls),
path('app1/', include('app1.urls', namespace='app1'))
]
它说
“ModuleNotFoundError: 没有名为‘app1’的模块”
如果我在此重组中遗漏了一个步骤和/或我是否在 url conf 中遗漏了某些内容,请有人建议?
【问题讨论】:
标签: python django configuration