SORU
21 Mart 2013, PERŞEMBE


Django DB Ayarları 'Yanlış Yapılandırılmış' Hata

Django (1.5) çalışıyor gayet iyi benim için, ama ne zaman ateşle Python yorumlayıcısı (Python 3) için kontrol bazı şeyler, çok garip bir hata denerim alma - from django.contrib.auth.models import User -

Traceback (most recent call last):
  File "/usr/local/lib/python3.2/dist-packages/django/conf/__init__.py", line 36, in _setup
    settings_module = os.environ[ENVIRONMENT_VARIABLE]
  File "/usr/lib/python3.2/os.py", line 450, in __getitem__
    value = self._data[self.encodekey(key)]
KeyError: b'DJANGO_SETTINGS_MODULE'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.2/dist-packages/django/contrib/auth/models.py", line 8, in <module>
    from django.db import models
  File "/usr/local/lib/python3.2/dist-packages/django/db/__init__.py", line 11, in <module>
    if settings.DATABASES and DEFAULT_DB_ALIAS not in settings.DATABASES:
  File "/usr/local/lib/python3.2/dist-packages/django/conf/__init__.py", line 52, in __getattr__
    self._setup(name)
  File "/usr/local/lib/python3.2/dist-packages/django/conf/__init__.py", line 45, in _setup
    % (desc, ENVIRONMENT_VARIABLE))

django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, 
  but settings are not configured. You must either define the environment 
  variable DJANGO_SETTINGS_MODULE or call settings.configure() 
  before accessing settings.

Nasıl Python yorumlayıcısı dışında gayet iyi çalışıyor zaman yanlış yapılandırılmış olabilir mi? Django ayarlarımı, DATABASES ayarlar şunlardır:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'django_db', # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        'USER': 'zamphatta',
        'PASSWORD': 'mypassword91',
        'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '', # Set to empty string for default.
    }
}

...bu nasıl yanlış yapılandırılmış mı?

CEVAP
21 Mart 2013, PERŞEMBE


Sadece python ateş ve her şeyi kontrol, django çalışmak istediğini bilmiyor olamazsın. Bu şeylerden birini yapmak zorundasınız:

  • python manage.py shell kullanın
  • django-admin.py shell --settings=mysite.settings (ya da her neyse ayarları kullanın modülü) kullanın
  • mysite.settings OS DJANGO_SETTINGS_MODULE ortam değişkeni ayarlayın
  • (Bu django 1.6 kaldırılır) python yorumlayıcı: setup_environ Kullanın

    from django.core.management import setup_environ
    from mysite import settings
    
    setup_environ(settings)
    

Doğal olarak, ilk yol kolay olur.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • friendz.net

    friendz.net

    29 EKİM 2010
  • Greater Than Gatsby Photoshop Actions & Lightroom Presets

    Greater Than

    11 ŞUBAT 2013
  • Random Act of Kindness Video Contest

    Random Act o

    18 EYLÜL 2012