Django不能导入设置'myfolder.settings'

时间:2022-03-18 01:06:59

I'm using Django 1.4 and have the lay-out as recommended.

我使用的是Django 1.4,并按照建议进行了布局。

mysite/
     manage.py

     mysite/
        __init__.py
        settings.py
        urls.py
        wsgi.py
     myapp/
        __init__.py
        models.py
        admin.py
        views.py

This is the error i get when i run syncdb

这是运行syncdb时得到的错误

raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'mysite.settings' (Is it on sys.path?): No module  named mysite.settings

I'll have set os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") in wsgy and in manage files

我要设置os.environ。在wsgy和manage files中设置默认值(“DJANGO_SETTINGS_MODULE”,“mysite.settings”)

I'm using Visual Studio 2013 with PyTools

我在使用PyTools的Visual Studio 2013

1 个解决方案

#1


1  

For that to work you need to define your PYTHONPATH first.

要实现这一点,首先需要定义PYTHONPATH。

Here's something to read: http://www.stereoplex.com/blog/understanding-imports-and-pythonpath and http://www.tutorialspoint.com/python/python_modules.htm, but I'm sure you can google it!

这里有一些东西值得一读:http://www.stereoplex.com/blog/understand - important -and-pythonpath和http://www.tutorialspoint.com/python/python_modules.htm,但是我相信您可以谷歌!

  1. For Windows 7, you need to go to your Computer icon, right-click, choose Properties;
  2. 对于Windows 7,你需要打开电脑图标,右键单击,选择Properties;
  3. Pick "Advanced system settings";
  4. 选择“高级系统设置”;
  5. In the "Advanced" Tab, click the "Environment Variables";
  6. 在“高级”选项卡中,单击“环境变量”;
  7. Create a new "System variable";
  8. 创建一个新的“系统变量”;
  9. Name it PYTHONPATH ... put a value like "c:\projects;c\projects\mysite";
  10. 名字PYTHONPATH环境…例如“c:\项目;c\项目”;
  11. You can test it by opening a command prompt window and type in "echo %PYTHONPATH%";
  12. 您可以通过打开命令提示窗口并输入“echo %PYTHONPATH%”来测试它;

If you're not familiar with what I've described above, you need to read more.

如果你不熟悉我上面描述的内容,你需要多读一些。

#1


1  

For that to work you need to define your PYTHONPATH first.

要实现这一点,首先需要定义PYTHONPATH。

Here's something to read: http://www.stereoplex.com/blog/understanding-imports-and-pythonpath and http://www.tutorialspoint.com/python/python_modules.htm, but I'm sure you can google it!

这里有一些东西值得一读:http://www.stereoplex.com/blog/understand - important -and-pythonpath和http://www.tutorialspoint.com/python/python_modules.htm,但是我相信您可以谷歌!

  1. For Windows 7, you need to go to your Computer icon, right-click, choose Properties;
  2. 对于Windows 7,你需要打开电脑图标,右键单击,选择Properties;
  3. Pick "Advanced system settings";
  4. 选择“高级系统设置”;
  5. In the "Advanced" Tab, click the "Environment Variables";
  6. 在“高级”选项卡中,单击“环境变量”;
  7. Create a new "System variable";
  8. 创建一个新的“系统变量”;
  9. Name it PYTHONPATH ... put a value like "c:\projects;c\projects\mysite";
  10. 名字PYTHONPATH环境…例如“c:\项目;c\项目”;
  11. You can test it by opening a command prompt window and type in "echo %PYTHONPATH%";
  12. 您可以通过打开命令提示窗口并输入“echo %PYTHONPATH%”来测试它;

If you're not familiar with what I've described above, you need to read more.

如果你不熟悉我上面描述的内容,你需要多读一些。