If you import the django module in settings.py, you will get angry because there is no SECRET_KEY setting when replacing settings.
In settings.py ʻadd_to_builtins ('bootstrap3.templatetags.bootstrap3') If you write like this, you don't need to write
{% load bootstrap3%}` at the beginning of the template.
That's why I wrote it immediately.
from django.template.base import add_to_builtins
add_to_builtins('bootstrap3.templatetags.bootstrap3')
django can change the settings it uses by passing the --settings
option when executing the manage.py
command.
By using this, prepare the settings for test and the settings for deploy, and when starting in the test environment or production environment
$ python manage.py runserver --settings=myproject.settings_production
Execute as follows.
Reference: In the case of gunicorn, it looks like this
$ gunicorn -w 2 myproject.wsgi:application --settings=myproject.settings_production --bind=unix:///tmp/myproject.sock
Since the settings for the production environment are different from the DEBUG flag and DB, Import the default settings as shown below and overwrite only the necessary variables.
from .settings import *
DEBUG = False
ALLOWED_HOSTS = ['*']
DATABASES = {
'default': {
...
}
}
Background 1 (import django.template.base in settings.py) and background 2 (replace settings)
The following error is thrown and dropped.
import django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
I called django in settings, and then called settings in it, so It seems that the import of default settings was suppressed by infinite loop prevention.
Execute ʻadd_to_builtinsin settings.py seems to be bad, so move to
myproject / __ init__.py. However, if you run it with gunicorn, you may get angry if you don't have the
DJANGO_SETTINGS_MODULE environment variable when you import django in
myproject / __ init__.py` (depending on the module you load).
ImproperlyConfigured: Requested setting BOOTSTRAP3, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
\ # bootstrap3 seems to read settings inside.
So, the contents of myproject / __ init__.py
considering the start of gunicorn are like this.
import os
from django.template.base import add_to_builtins
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mailer.settings")
add_to_builtins('bootstrap3.templatetags.bootstrap3')
Recommended Posts