0

Django version 1.8.4

I was going for a django setup similar to one mentioned by "MiniQuark" here for my initial setup...

How to manage local vs production settings in Django?

Here is my project structure:

project
  manage.py
  - project
    settings.py
    production.py
    development.py
    __init__.py
    url.py
    wsgi.py

My settings file has all main settings, then on "development.py" I have...

from __future__ import absolute_import # optional, but I like it
from .settings import *

# Development overrides
DEBUG = True

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

Then on my "init.py" file(which is ignored by git as mentioned in link)...

from __future__ import absolute_import
from .development import *

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '(!z9pvx6&#4vm_wic3(n8*$m0bqer&^2913=1y!776e9b=-&#z'

Is it not possible to do it this way? As it doesn't recognise the secret_key mentioned on the init file?

raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
Community
  • 1
  • 1
polarcare
  • 575
  • 1
  • 6
  • 24

1 Answers1

0

In the link you mention, all the settings files are under a settings folder, not in project as you describe above.

Laurent S
  • 4,106
  • 3
  • 26
  • 50
  • I created a "settings" folder and moved "settings.py", "development.py", "production.py" and "__init__.py" into it and now when I try runserver it says "ImportError: No module named settings"? – polarcare Sep 20 '15 at 18:08
  • I renamed "settings/settings.py" to "settings/common.py". Then I changed "manage.py" to read "os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.common")" and now I am back to the original error, title of this post. – polarcare Sep 20 '15 at 18:47
  • 1
    The `init.py` file should be `__init__.py` (with double underscores before and after "init", so that python recognizes it as a module. Then your imports should work. – Laurent S Sep 20 '15 at 19:22
  • It is double underscore __init__.py, stackoverflow removes them when I comment for some reason. It doesn't seem to recognise my development.py file or the __init__.py – polarcare Sep 21 '15 at 07:52
  • 1
    by the way, shouldn't it be `"os.environ.setdefault("DJANGO_SETTINGS_MODULE", "yourapp.settings")"` instead of `settings`? – Laurent S Sep 21 '15 at 10:05
  • Hi Laurent, yes you are correct. I had the "settings" folder I created as a sibling of my project folder. I moved the "settings" folder i created into the "project" folder, set "os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")" and everything seems to work now. Thanks for the help. – polarcare Sep 21 '15 at 20:47
  • glad to help! feel free to accept the answer if it helped :) – Laurent S Sep 22 '15 at 21:41