gpt4 book ai didi

django - 导入错误 : Could not import settings - No module named settings

转载 作者:行者123 更新时间:2023-12-02 15:28:01 27 4
gpt4 key购买 nike

我似乎遇到了一个基本的路径问题,但我这辈子都弄不明白。

我有以下目录结构:

    └── rockitt
├── activities
│   ├── migrations
│   ├── templates
│   │   └── activities
│   └── templatetags
├── blog
│   ├── settings

blog/settings 我有:base.py dev.py __init.py__

上面目录中的

__init.py__ 包含:从 .dev 导入 *

当运行诸如 manage.py 之类的东西时,我收到以下错误:

ImportError: Could not import settings 'blog.settings' (Is it on sys.path? Is there an import error in the settings file?): 没有名为 settings 的模块

到目前为止我尝试了什么:

  1. 我检查了 manage.py 运行时存在的路径,以下路径位于列表顶部:
    罗基特
    lib/python2.7/Django-1.7.7-py2.7.egg
    库/python2.7
    [其他目录...]
    ENV/lib/python27.zip
    环境/lib/python2.7
    ENV/lib/python2.7/plat-linux2
    ENV/lib/python2.7/lib-tk
    ENV/lib/python2.7/lib-old
    ENV/lib/python2.7/lib-dynload
    /usr/local/lib/python2.7
    /usr/local/lib/python2.7/plat-linux2
    /usr/local/lib/python2.7/lib-tk
    ENV/lib/python2.7/site-packages

  2. 我曾尝试手动加载设置文件,但没有成功:从我尝试过的 blog/settings 目录(我不确定这是否是测试这个的正确方法但是基于阅读 this :

    >>> import dev
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "dev.py", line 1, in <module>
    from .base import *
    ValueError: Attempted relative import in non-package

我有点卡在这上面了。我 -=think=- 它可能也与我的 wsgi.py 文件有关(如下)。

更多信息:

  1. wsgi.py:

    import os, sys, site
    site.addsitedir('/home/thisUserName/webapps/dev_django_rockitt/ENV/lib/python2.7/site-packages')
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "blog.settings.dev")
    activate_this = os.path.expanduser("/home/thisUserName/webapps/dev_django_rockitt/ENV/bin/activate_this.py")
    execfile(activate_this, dict(__file__=activate_this))

    #calculate the path based on the location of the WSGI script
    project = '/home/thisUserName/webapps/dev_django_rockitt/rockitt'
    workspace = os.path.dirname(project)
    sys.path.append(workspace)
    sys.path = ['/home/thisUserName/webapps/dev_django_rockitt/rockitt/blog', '/home/thisUserName/webapps/dev_django_rockitt/rockitt'$

    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()
  2. 堆栈跟踪:

    Traceback (most recent call last):
    File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
    File "/home/thisUserName/webapps/dev_django_rockitt/lib/python2.7/Django-1.7.7-py2.7.egg/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
    File "/home/thisUserName/webapps/dev_django_rockitt/lib/python2.7/Django-1.7.7-py2.7.egg/django/core/management/__init__.py", line 345, in execute
    settings.INSTALLED_APPS
    File "/home/thisUserName/webapps/dev_django_rockitt/lib/python2.7/Django-1.7.7-py2.7.egg/django/conf/__init__.py", line 46, in __getattr__
    self._setup(name)
    File "/home/thisUserName/webapps/dev_django_rockitt/lib/python2.7/Django-1.7.7-py2.7.egg/django/conf/__init__.py", line 42, in _setup
    self._wrapped = Settings(settings_module)
    File "/home/thisUserName/webapps/dev_django_rockitt/lib/python2.7/Django-1.7.7-py2.7.egg/django/conf/__init__.py", line 98, in __init__
    % (self.SETTINGS_MODULE, e)
    ImportError: Could not import settings 'blog.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named settings

最佳答案

由于我自己的愚蠢,我很想删除这个问题,但我认为这个答案可能会对其他正在编码且 sleep 不足的人有所帮助。

这真的很简单 - 这是 blog/settings 目录中的错字

我输入了 __init.py__,但显然它应该是 __init__.py

纠正后,错误就消失了。

我希望这对将来的人有所帮助。捂脸时刻。

关于django - 导入错误 : Could not import settings - No module named settings,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29401910/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com