我安装了bootstrap4
$ pip install django-bootstrap4
它正在安装在此目录中
C:\Users\trade\techpit-match-env\Lib\site-packages
Django似乎正在查看此目录
C:\Users\trade\Anaconda3\lib\site-packages\django
当我将'bootstrap4'放入INSTALLED_APPS =('bootstrap4')变量然后运行时
$ python manage.py runserver
我收到此错误
C:\Users\trade\techpit-match-env\Scripts\techpit>python manage.py runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x000001C4D8F65488>
Traceback (most recent call last):
File "C:\Users\trade\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\trade\Anaconda3\lib\site-packages\django\core\management\commands\runserver.py", line 113, in inner_run
autoreload.raise_last_exception()
File "C:\Users\trade\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 248, in raise_last_exception
raise _exception[1]
File "C:\Users\trade\Anaconda3\lib\site-packages\django\core\management\__init__.py", line 327, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\trade\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\trade\Anaconda3\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\trade\Anaconda3\lib\site-packages\django\apps\registry.py", line 89, in populate
app_config = AppConfig.create(entry)
File "C:\Users\trade\Anaconda3\lib\site-packages\django\apps\config.py", line 90, in create
module = import_module(entry)
File "C:\Users\trade\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'bootstrap4'
如何解决此错误? 我通过使用复制和粘贴在django文件夹中安装了bootstrap4,但这没有用。 任何帮助将不胜感激。
谢谢!
答案 0 :(得分:0)
python -m pip install bootstrap4
这会将pip定位在python模块路径上,从而确保将bootstrap4
安装在用于运行manage.py
命令的同一python环境中。参见this。
答案 1 :(得分:0)
我在做同样的课程,我得到了答案。 通过我检查的步骤:
我发现了一些有趣的东西。这是已安装的应用程序密钥 INSTALLED_APPS 的顺序。
此配置键无效:
INSTALLED_APPS = [
# own applications
'learning_logs',
'users',
# 3 party applications
'bootstrap4'
# django framework applications
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
但是这项工作
INSTALLED_APPS = [
# own applications
'learning_logs',
'users',
# django framework applications
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# 3 party applications
'bootstrap4'
]
将 'bootstrap4' 移到最后修复加载此库。
问候, 马辛
答案 2 :(得分:0)
在 settings.py INSTALLED_APPS 中检查“bootstrap 4”后是否有逗号
应该是这样的:
INSTALLED_APPS = [
# my apps
'learning_logs',
'users',
# outside apps
'bootstrap4',
# django apps
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]