I'm using django-rosetta app, it works on development without a CACHES setting, but on prod I've this setting as follow:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
}
}
The problem is that under prod it raises me
django.core.exceptions.ImproperlyConfigured:
You can't use the CacheRosettaStorage if your cache isn't correctly set up,
please double check your Django DATABASES setting and that the cache server is responding
The database setting is simple as
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
So, as the exception message sais:
double check your Django DATABASES setting and that the cache server is responding
I did it, even my memchached was working correctly I decided reinstall it, and, as magic art, it worked!
Before that I changed my CACHES
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
},
'rosetta': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': '/var/tmp/django_cache',
}
}
Django rosetta will use a key rosetta if a cache with this name exists, or default if not. With the FileBasedCache it wasn't launch any error, so I realized the problem was with MemcachedCache. But, after reinstall it, it worked.
Related
I'm working on a Django application which uses django-pipeline for dealing with browsers' file caching issues (and also for other benefits).
STATIC_URL = '/static/'
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
STATICFILES_DIRS = (
os.path.join(PROJECT_ROOT, 'bower'),
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'pipeline.finders.PipelineFinder',
'pipeline.finders.CachedFileFinder',
)
PIPELINE = {}
PIPELINE['DISABLE_WRAPPER'] = True
PIPELINE['JS_COMPRESSOR'] = 'pipeline.compressors.NoopCompressor'
PIPELINE['CSS_COMPRESSOR'] = 'pipeline.compressors.yuglify.YuglifyCompressor'
PIPELINE['COMPILERS'] = (
'pipeline.compilers.sass.SASSCompiler',
'pipeline.compilers.es6.ES6Compiler',
)
PIPELINE['JAVASCRIPT'] = {
...
}
PIPELINE['STYLESHEETS'] = {
...
}
PIPELINE['SASS_BINARY'] = 'C:\\Ruby22-x64\\bin\\sass.bat'
PIPELINE['BABEL_BINARY'] = 'c:\\Users\\Foobar\\node_modules\\.bin\\babel.cmd'
So far so good. Lately we decided to use Django's Database Cache (https://docs.djangoproject.com/en/1.9/topics/cache/#database-caching) for caching some long running statistical calculation results.
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
'LOCATION': 'django_dbcache',
}
}
I executed createcachetable and the table was created. I'm placing entries into this table with no expiration date, since I have my own validity check, and can decide myself if the data is up-to-date, or needs to be recalculated.
To my surprise however, when I issue a collectstatic for pipeline, it wipes the content of that table and fills it with it's own staticfiles:{md5code} key-values. (In production I saw situation when it didn't wipe out everything). But this renders my caching scheme non functional. I cannot seem to find any settings in the pipeline documentation how to stop pipeline doing this. pipeline's cache entry values in the cache are pretty short, merely contain full path to generated files. These entries' expiration are a couple of hours. I won't mind them being there, just don't wipe my stuff.
Additional note: I'm on Windows platform (see the pipeline settings above), but the same thing happens on a Linux production server.
Addition to the marked answer: knowing that anyone can mess with the default cache + staticfiles can rudely wipe it out, it's even better to separate ours and everyone else:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'default-cache',
},
'staticfiles': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'static-files',
},
'my_dbcache': {
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
'LOCATION': 'django_dbcache',
}
}
Defining a separate cache for static files will fix the issue. Django by default looks for "staticfiles" cache first.
example:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
'LOCATION': 'django_dbcache',
},
'staticfiles': {
'BACKEND': "django.core.cache.backends.locmem.LocMemCache",
'LOCATION': 'static-files',
}
I'm trying to run
python manage.py syncdb
but i'm getting this error:
There is no South database module 'south.db.sqlite3'
This is my settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
SOUTH_DATABASE_ADAPTERS = {
'default': 'south.db.sqlite3'
}
You may be able to address this by specifically installing Django 1.6 with pip install django==1.6.
You may also have luck if you add
SOUTH_DATABASE_ADAPTERS = {
'default': 'south.db.sqlite3'
}
If that don't work may be your answer can be here :
http://answerhub.com/qa/questions/28185/how-do-i-get-syncdb-to-work-im-getting-there-is-no.html
I tried setting
DATABASES = {
'default': {
'NAME': 'db',
'ENGINE': 'mysql.connector.django',
'USER': 'dbuser',
'PASSWORD': 'dbpass',
'OPTIONS': {
'autocommit': True,
'init_command' : 'SET storage_engine=INNODB',
},
}
}
(UPD: updated the above code so ppl won't get confused that I am not using django settings the right way)
in Django settings, but this backend doesn't accept such connection option...
http://dev.mysql.com/doc/connector-python/en/connector-python-connectargs.html
is there any other way of doing this?
First, to use MySQL Connector/Python Django backend, you have to set the ENGINE setting to mysql.connector.django:
DATABASE = {
'default': {
..
'ENGINE': 'mysql.connector.django',
..
}
}
Indeed, MySQL Connector/Python does not have the init_command connection argument. I can see value in adding an option for setting the default storage engine in the Django OPTIONS though. If you really want it, I would suggest opening a feature request on http://bugs.mysql.com.
Small note that MySQL 5.6 (and if you start out, you should use this version) has storage engine set to InnoDB by default.
You need to set the entire setting:
DATABASES = {
'default': {
'NAME': "MyDatabaseName,
'ENGINE': 'django.db.backends.mysql',
'USER': "MyUsername",
'PASSWORD': "MyPassword",
'HOST': "MyHostName",
'OPTIONS': {'init_command': 'SET storage_engine=INNODB'},
}
}
I'm setting up a Django application and I want to use SQL Server 2012 for my database.
To configure my website I'm following this section of the official Django documentation.
In the section Database setup I found instructions for changing RDBMS.
And in settings.py file I found these instructions for setting up Django with SQlite.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
How I can change this configuration to use SQL Server 2012 instead?
Looks like you'll need django-mssql which requires django 1.4 or below:
http://django-mssql.readthedocs.org/en/latest/
It has a pip package: https://pypi.python.org/pypi/django-mssql
Then include in your settings.py:
DATABASES = {
'default': {
'NAME': 'my_database',
'ENGINE': 'sqlserver_ado',
'HOST': 'dbserver\\ss2008',
'USER': '',
'PASSWORD': '',
}
}
In my settings.py I have:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
'LOCATION': 'ws_cache_table',
'TIMEOUT': '3000000',
'OPTIONS': {
'MAX_ENTRIES': 10000000
}
}
}
But if I do this in python manage.py shell:
from django.core.cache import cache
print type(cache)
I'm getting:
django.core.cache.backends.locmem.LocMemCache
Why!???
Now I can't clear my cache...
To prove my configuration is corect I can do:
from django.conf import settings
conf = settings.CACHES.get('default', None)
And I'm getting:
{'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
'LOCATION': 'ws_cache_table',
'OPTIONS': {'MAX_ENTRIES': 10000000},
'TIMEOUT': '3000000'}
It looks like get_cache method is called before CACHES is defined...
First of all you should keep in mind that your local_settings.py would overwrite the settings.py.
Then you should watch out what cache daemon as backend is running, as there are different ones and depending what you run you need the respective specified option.
e.g. for memcached the local_settings.py would read:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211'
'CACHE_TIME': '3600',
}
}
whereas for locmem:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'
'LOCATION': '127.0.0.1:11211'
'TIMEOUT': 3600'
}
}