为什么我的第二个应用不想导入到第一个应用Django

xsuvu9jc  于 2022-11-18  发布在  Go
关注(0)|答案(1)|浏览(133)
File "C:\python mini\PyCharm Community Edition 2021.1.1\MyBlog\mysite\mysite\urls.py", line 3, in <module>
    from mysite.register import views
ModuleNotFoundError: No module named 'mysite.register'

为什么django看不到导入的app?也许我应该尝试设置mysite/blog url?x1c 0d1x项目结构:我settings.py天

from pathlib import Path
import os

BASE_DIR = Path(__file__).resolve().parent.parent
STATIC_DIR = os.path.join(BASE_DIR, 'static')
CRISPY_TEMPLATE_PACK = "bootstrap4"

STATIC_URL = '/static/'
SECRET_KEY = ''

DEBUG = True

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = [

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'blog',
    'menu',
    'register.apps.RegisterConfig',

]

mysite/urls.py

from django.contrib import admin
from django.urls import path, include
from mysite.register import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('blog.urls')),
    path("register/", views.register, name="register"),
]

如果我试着只写from register import views`导入用红色下划线

bxgwgixi

bxgwgixi1#

我发现问题了。我只是把两行...... path('', include('blog.urls')),换成了path("register/", views.register, name="register"),。同时导入的from register import views有红色下划线

相关问题