django-settings

Why is django's settings object a LazyObject?

我的梦境 提交于 2019-11-30 04:07:32
问题 Looking in django.conf I noticed that settings are implemented like this: class LazySettings(LazyObject): ... What is the rationale behind making settings objects lazy? 回答1: Check out this section of the Django coding style. The reason is explained in there (quoted below). In addition to performance, third-party modules can modify settings when they are imported. Accessing settings should be delayed to ensure this configuration happens first. Modules should not in general use settings stored

Running a standalone script doing a model query in Django with `settings/dev.py` instead of `settings.py`

若如初见. 提交于 2019-11-29 15:02:05
问题 Note the settings/dev.py instead of one settings.py file and the script.py in my_app in the following Django(1.4.3) project: . ├── my_project │ ├── my_app │ │ ├── __init__.py │ │ ├── models.py │ │ ├── tests.py │ │ ├── views.py │ │ └── script.py │ ├── __init__.py │ ├── settings │ │ ├── dev.py │ │ ├── __init__.py │ │ └── prod.py │ ├── urls.py │ └── wsgi.py ├── manage.py └── requirements.txt When I only had one settings.py file in place of the settings folder I was able to run the following

Cannot get environment variables in Django settings file

送分小仙女□ 提交于 2019-11-29 06:12:46
I'm trying to read some environment variables in Django settings, which i have defined in /home/user/.bashrc (and latter in /etc/bash.bashrc ) , but all i get is a KeyError exception. I know my environment variables are set, because i can print them in the terminal (echo $VAR_NAME). This should be trivial. This is the code i'm using. from django.core.exceptions import ImproperlyConfigured msg = "Set the %s environment variable" def get_env_variable(var_name): try: return os.environ[var_name] except KeyError: error_msg = msg % var_name raise ImproperlyConfigured(error_msg) OS_DB_USER = get_env

Specify Django Test Database names in settings.py

守給你的承諾、 提交于 2019-11-29 05:27:36
I'm specifying the databases using a python object: DATABASES = { 'default':{ 'ENGINE':'mysql', 'NAME':'testsqldb', 'USER':'<username>', 'PASSWORD':'<password>', }, 'dynamic_data':{ 'ENGINE': 'sqlite3', 'NAME':'', 'USER':'', 'PASSWORD':'' }, } How can I specify the name of my test database? I've been trying to use TEST_NAME = 'auto_tests' in the settings.py file. However, when I run python manage.py tests <app_name> I get the following message: Creating test database 'default'... Got an error creating the test database: (1007, "Can't create database 'test_testsqldb'; database exists") Type

Django: “No module named context_processors” error after reboot

南笙酒味 提交于 2019-11-29 02:55:08
I have a Django site that works on my PC, and was working briefly on my server after loading it on. I noticed my server had Django 1.6 and I upgraded to 1.8. After rebooting, none of the pages on my site load and I get the error: ImportError No module named context_processors I read through the docs on Django and allauth. Django mentions that in 1.8 the context_processors moved and allauth says specific allauth tags are no longer needed in the TEMPLATE_CONTEXT_PROCESSORS of settings.py . Django: https://docs.djangoproject.com/en/1.8/ref/settings/ Allauth: https://django-allauth.readthedocs.org

how can I check database connection to mysql in django

我的梦境 提交于 2019-11-29 01:38:16
how can I do it? I thought, I can read something from database, but it looks too much, is there something like?: settings.DATABASES['default'].check_connection() All you need to do is start a application and if its not connected it will fail. Other way you can try is on shell try following - from django.db import connections from django.db.utils import OperationalError db_conn = connections['default'] try: c = db_conn.cursor() except OperationalError: connected = False else: connected = True I use the following Django management command called wait_for_db : import time from django.db import

Django setting : psycopg2.OperationalError: FATAL: Peer authentication failed for user “indivo”

旧时模样 提交于 2019-11-29 01:29:10
问题 I am getting problem in Django project setting with POSTGRESQL. Here is my setting.py database setting DATABASES = { 'default':{ 'ENGINE':'django.db.backends.postgresql_psycopg2', # '.postgresql_psycopg2', '.mysql', or '.oracle' 'NAME':'indivo', # Required to be non-empty string 'USER':'indivo', # Required to be non-empty string 'PASSWORD':'ritvik', 'HOST':'', # Set to empty string for localhost. 'PORT':'', # Set to empty string for default. }, } Now in postgres backend what I have done is .

Why is Django throwing error “DisallowedHost at /”?

一个人想着一个人 提交于 2019-11-29 00:55:35
I am setting up my own Django server using this Digital Ocean tutorial . I created the Django framework following each step, and ran the server using this command: ./manage.py runserver 0.0.0.0:8000 When I tried to visit the IP at port 8000, the following error was shown: DisallowedHost at / Invalid HTTP_HOST header: 'XXX.XXX.XXX.XXX:8000'. You may need to add u'XXX.XXX.XXX.XXX' to ALLOWED_HOSTS. (IP substituted with X's) Why is this happening? randyr In your settings.py , there is a list called ALLOWED_HOSTS . You need to add the IP address you see in the error to that list: ALLOWED_HOSTS = [

how to point correctly to static image in django

安稳与你 提交于 2019-11-28 22:24:10
问题 I have a template that renders an image: {% load staticfiles %} <img src="{% static "img/logo.png" %}" alt="My image"/> The image link is broken, but it points to: localhost/static/img/logo.png What are values I need to set for static_root, static_url, and STATICFILES_DIRS to get this image to show up correctly? This is my directory structure: myprojectname (top level) --- myprojectname --- --- myproectname --- --- --- settings --- --- --- --- base.py (setting.py) --- --- static --- --- ---

How can I correctly set DJANGO_SETTINGS_MODULE for my Django project (I am using virtualenv)?

寵の児 提交于 2019-11-28 04:30:38
I am having some trouble setting the DJANGO_SETTINGS_MODULE for my Django project. I have a directory at ~/dev/django-project . In this directory I have a virtual environment which I have set up with virtualenv, and also a django project called "blossom" with an app within it called "onora". Running tree -L 3 from ~/dev/django-project/ shows me the following: . ├── Procfile ├── blossom │ ├── __init__.py │ ├── __init__.pyc │ ├── fixtures │ │ └── initial_data_test.yaml │ ├── manage.py │ ├── onora │ │ ├── __init__.py │ │ ├── __init__.pyc │ │ ├── admin.py │ │ ├── admin.pyc │ │ ├── models.py │ │ ├─