django-settings

Django @override_settings does not allow dictionary?

让人想犯罪 __ 提交于 2019-12-01 16:39:28
I am new to Python decorators so perhaps I am missing something simple, here is my situation: This works for me: def test_something(self): settings.SETTING_DICT['key'] = True #no error ... But this throws a "SyntaxError: keyword can't be an expression": @override_settings(SETTING_DICT['key'] = True) #error def test_something(self): ... Just to be clear, normal use of override settings works: @override_settings(SETTING_VAR = True) #no error def test_something(self): ... Is there a way to use the decorator with a settings dictionary, or am I doing something wrong? Thanks in advance! You should

How do you fix the following Django Error: “Type: IOError” “Value: [Errno 13] Permission denied”

烂漫一生 提交于 2019-12-01 08:38:06
I am following a Django Tutorial where you are required to construct some image thumbnails once an image is saved in admin. I am also using Python's tempfile module to save a temporary file name. However I keep running into the following error: "Type: IOError" "Value: [Errno 13] Permission denied: 'c:\\docume~1\\myname\\locals~1\\temp\\somefilename'" Here is the code I am using Settings MEDIA_ROOT = '/home/myname/projectname/media/' MEDIA_URL = 'http://127.0.0.1:8000/media/'enter code here models.py from string import join import os from PIL import Image as PImage from settings import MEDIA

Why is django's settings object a LazyObject?

老子叫甜甜 提交于 2019-11-30 20:27:17
Looking in django.conf I noticed that settings are implemented like this: class LazySettings(LazyObject): ... What is the rationale behind making settings objects lazy? Michael Mior 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 in django.conf.settings at the top level (i.e. evaluated when the module is imported). The

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

江枫思渺然 提交于 2019-11-30 10:06:26
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 script without any errors : script.py: ###################################################################

With DEBUG=False, how can I log django exceptions to a log file

吃可爱长大的小学妹 提交于 2019-11-30 08:18:57
问题 With DEBUG=True, Django exceptions dump to stderr, which is typically sent to a rotating log file by the web server. With DEBUG=False, Django instead emails the exception to the the ADMINS=. How can I retain the DEBUG=True behavior with DEBUG=False? I've read How do you log server errors on django sites and How can I see error logs of Django views and How do you log server errors on django sites. The answer seems to involve some middleware. Is there a code snippet available, or are these

Cannot get environment variables in Django settings file

徘徊边缘 提交于 2019-11-30 08:06:31
问题 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]

Specify Django Test Database names in settings.py

前提是你 提交于 2019-11-30 07:46:42
问题 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

Django settings.py variables in templates

a 夏天 提交于 2019-11-30 04:47:52
问题 I'm encountering a very strange error. I have an app ID defined in my settings.py file like so: CARDSPRING_APP_ID = '################' This works on nearly every page in my site, except for one. Strangely enough, other variables work. In a script section on the page, I have the following: alert("cs appid=" + {{ CARDSPRING_APP_ID }} + " sectoken=" + {{ securityToken }} + " timestamp= " +{{ timestamp }} + " hash = " + {{ digestedHash }} + " ccnum " + $('.card-number').val() + " exp" + $('

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

我们两清 提交于 2019-11-30 04:41:20
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 . rohit@rohit-desktop:~$ sudo su - postgres postgres@rohit-desktop:~$ createuser --superuser indivo #

how to point correctly to static image in django

倖福魔咒の 提交于 2019-11-30 04:09:34
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 --- --- --- img This is my static configuration in settings: STATIC_ROOT = '/Users/myuser/myprojectname