运行这个 django 项目,但它在 manage.py 中向我显示了这个错误

Posted

技术标签:

【中文标题】运行这个 django 项目,但它在 manage.py 中向我显示了这个错误【英文标题】:running this django project but its showing me this error in manage.py 【发布时间】:2021-03-10 22:14:21 【问题描述】:

这是它在运行可搜索下拉列表的 django 项目时向我显示的错误。我完全按照 youtube 视频中提到的那样做,但这些都是它向我展示的所有错误

File "manage.py", line 23, in <module>
    main()
  File "manage.py", line 19, in main
    execute_from_command_line(sys.argv)
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\core\management\__init__.py", line 345, in execute
    settings.INSTALLED_APPS
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\conf\__init__.py", line 83, in __getattr__
    self._setup(name)
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\conf\__init__.py", line 70, in _setup
    self._wrapped = Settings(settings_module)
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\conf\__init__.py", line 177, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "C:\ProgramData\Anaconda3\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 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\mahima\Downloads\dropdown\ddl\ddl\settings.py", line 58, in <module>
    'DIRS': [os.path.join(BASE_DIR,'templates')],
NameError: name 'os' is not defined

这是我的 manage.py 文件。我已经安装了 mysql。谁能告诉我如何解决所有这些错误?我是新人

#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ddl.settings')
    
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

【问题讨论】:

设置中出现错误。py 无法管理,py 【参考方案1】:

尝试在文件顶部添加 C:\Users\mahima\Downloads\dropdown\ddl\ddl\settings.py

import os

看起来你错过了模块的导入

【讨论】:

好的,谢谢。我这样做了,但现在它向我展示了这个> ``` django.db.utils.OperationalError: (1045, "Access denied for user 'mahima'@'localhost' (using password: YES)") ```

以上是关于运行这个 django 项目,但它在 manage.py 中向我显示了这个错误的主要内容,如果未能解决你的问题,请参考以下文章

008:第一个Django项目剖析

django-geoposition 地图小部件未显示在我的生产服务器上的 django 管理员中,但它在我的测试服务器上运行良好

我创建了一个 django 软件,它在 localhost 上运行,但不能在 heroku 上工作,它的日志显示了这个

python命令行运行django项目, can't open file 'manage.py' 问题解决

django创建项目后,项目名称的目录下还有一个项目名称的文件夹?manage.py在文件夹外。

Django makemigrations 未检测到项目/应用程序/myapp