2016-02-23 5 views
0

ma structure de projet django est illustré ci-dessous,configuration des paramètres django après avoir déplacé vers un autre répertoire?

. 
├── myapp 
│   ├── apps 
│   │   └── __init__.py 
│   ├── __init__.py 
│   ├── settings.py 
│   ├── urls.py 
│   └── wsgi.py 
├── manage.py 
└── tests 
    └── test_config.py 

où je me suis déplacé fichier de paramètres pour former la structure ci-dessous.

. 
├── myapp 
│   ├── apps 
│   │   └── __init__.py 
│   ├── config 
│   │   ├── __init__.py 
│   │   ├── settings.py 
│   │   ├── urls.py 
│   │   └── wsgi.py 
│   └── __init__.py 
├── manage.py 
└── tests 
    └── test_config.py 

donc je changé mon wsgi.py

import os 

from django.core.wsgi import get_wsgi_application 

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.config.settings") 

application = get_wsgi_application() 

et et mon manage.py

#!/usr/bin/env python 
import os 
import sys 

if __name__ == "__main__": 
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.config.settings") 

    print "settings!!" 

    from django.core.management import execute_from_command_line 

    execute_from_command_line(sys.argv) 

maintenant quand je lance le shell django avec ./manage.py shell je reçois cette erreur, le retraçage affiché ci-dessous.

Python 2.7.10 (default, Oct 14 2015, 16:09:02) 
[GCC 5.2.1 20151010] on linux2 
Django 1.9.2 
Traceback (most recent call last): 
    File "<input>", line 5, in <module> 
    File "/home/marty/.virtualenvs/seventeen/local/lib/python2.7/site-packages/django/__init__.py", line 17, in setup 
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING) 
    File "/home/marty/.virtualenvs/seventeen/local/lib/python2.7/site-packages/django/conf/__init__.py", line 55, in __getattr__ 
    self._setup(name) 
    File "/home/marty/.virtualenvs/seventeen/local/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup 
    % (desc, ENVIRONMENT_VARIABLE)) 
ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings 

Quel est le problème ici? Comment puis-je réparer ça?

grâce

+0

Je viens de créer un projet Django avec une structure identique à celle de votre question, et je peux courir très bien shell manage.py. Pourriez-vous essayer de supprimer les fichiers * .pyc? –

Répondre

2

myapp est pas PYTHONPATH, donc myapp.config.settings n'est pas un module valide.

Avant le os.environ, ajoutez les lignes suivantes:

import sys 
sys.path.append('path/to/dir/of/myapp') 
+0

ça ne marche pas! – Marty

+0

juste pour être sûr: si vous avez "/ home/username/myprojects/myapp" alors sys.path.append ("/ home/username/myprojects /")? –

+0

Splendide! Bon conseil – Rickka