Django Shell No module named settings

后端 未结 12 1365
温柔的废话
温柔的废话 2020-12-02 20:26

I\'ve deployed Django to Apache via mod_wsgi. Django is running fine when hosted from Apache. However, I\'m trying to do some maintenance via manage.py

12条回答
  •  一生所求
    2020-12-02 21:15

    This can happen if your root directory name is the same as the name of one of your apps. For example here I have a directory called bar containing a Django project with an app also called bar:

    Simons-MacBook-Pro ~/temp
    $ cd bar
    
    Simons-MacBook-Pro ~/temp/bar
    $ ./manage.py shell
    Error: Could not import settings 'bar.settings' (Is it on sys.path?): No module named settings
    
    Simons-MacBook-Pro ~/temp/bar
    $ ls -l
    total 48
    -rw-r--r--  1 simon  staff     0 25 Oct 10:46 __init__.py
    -rw-r--r--  1 simon  staff   130 25 Oct 10:46 __init__.pyc
    drwxr-xr-x  7 simon  staff   238 25 Oct 10:46 bar
    -rwxr-xr-x  1 simon  staff   503 25 Oct 10:46 manage.py
    -rw-r--r--  1 simon  staff  5025 25 Oct 10:46 settings.py
    -rw-r--r--  1 simon  staff  2658 25 Oct 10:46 settings.pyc
    -rw-r--r--  1 simon  staff   556 25 Oct 10:46 urls.py
    

    Changing the root directory's name to foo (or anything else other than bar) solves the problem:

    Simons-MacBook-Pro ~/temp/bar
    $ cd ..
    
    Simons-MacBook-Pro ~/temp
    $ mv bar foo
    
    Simons-MacBook-Pro ~/temp
    $ cd foo
    
    Simons-MacBook-Pro ~/temp/foo
    $ ./manage.py shell
    Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) 
    [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    (InteractiveConsole)
    >>> 
    

提交回复
热议问题