我必须开始学习django,并且在启动localhost时遇到了问题。 我得到的错误是:-
C:\Users\acer\Desktop\Example>py manage.py runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x0637DC90>
Traceback (most recent call last):
File "C:\Users\acer\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\acer\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\acer\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\autoreload.py", line 248, in raise_last_exception
raise _exception[1]
File "C:\Users\acer\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\__init__.py", line 337, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\acer\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\acer\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\acer\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\apps\registry.py", line 89, in populate
app_config = AppConfig.create(entry)
File "C:\Users\acer\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\apps\config.py", line 116, in create
mod = import_module(mod_path)
File "C:\Users\acer\AppData\Local\Programs\Python\Python37-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'pages.app'
我的代码中的错误是下面显示的include语句
from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('pages.urls')),
]
如果您知道解决方案,请提供帮助。...
答案 0 :(得分:0)
只需将您的应用程序包含在INSTALLED_APPS
文件的Settings.py
列表中。您的服务器无法获取您的应用程序并引起问题。
INSTALLED_APPS = [
'pages'
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
答案 1 :(得分:0)
您需要在settings.py文件的“ INSTALLED_APPS”中添加您的应用。
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'pages']