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`导入用红色下划线
1条答案
按热度按时间bxgwgixi1#
我发现问题了。我只是把两行......
path('', include('blog.urls')),
换成了path("register/", views.register, name="register"),
。同时导入的from register import views
有红色下划线