欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

新建的Django项目运行时报错

程序员文章站 2022-03-21 18:32:51
用Pycharm新建了一个Django项目,试图运行时报错,信息如下:"D:\Python\bin\runnerw64.exe" "D:\Python\Python 3.8.5\python.exe" D:/Python/WebStuManage/manage.py runserver 8000Traceback (most recent call last): File "D:/Python/WebStuManage/manage.py", line 22, in ...

用Pycharm新建了一个Django项目,试图运行时报错,信息如下:

"D:\Python\bin\runnerw64.exe" "D:\Python\Python 3.8.5\python.exe" D:/Python/WebStuManage/manage.py runserver 8000
Traceback (most recent call last):
  File "D:/Python/WebStuManage/manage.py", line 22, in <module>
    main()
  File "D:/Python/WebStuManage/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "D:\Python\Python 3.8.5\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "D:\Python\Python 3.8.5\lib\site-packages\django\core\management\__init__.py", line 345, in execute
    settings.INSTALLED_APPS
  File "D:\Python\Python 3.8.5\lib\site-packages\django\conf\__init__.py", line 83, in __getattr__
    self._setup(name)
  File "D:\Python\Python 3.8.5\lib\site-packages\django\conf\__init__.py", line 70, in _setup
    self._wrapped = Settings(settings_module)
  File "D:\Python\Python 3.8.5\lib\site-packages\django\conf\__init__.py", line 177, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "D:\Python\Python 3.8.5\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "D:\Python\WebStuManage\WebStuManage\settings.py", line 57, in <module>
    'DIRS': [os.path.join(BASE_DIR, 'templates')]
NameError: name 'os' is not defined

Process finished with exit code 1

事实上,归根结底时最后的NameError提示,只需在settings.py中加入

import os

即可。

本文地址:https://blog.csdn.net/qq_45853731/article/details/107891151