I'm trying to setup a simple API using Django Rest Framework, the problem is that my API does not have any database but the framework won't work without database setting.
Here is my Django Rest Framework configuration in settings.py
:
INSTALLED_APPS = [
'provider',
'django_nose',
'rest_framework',
'django.contrib.contenttypes',
]
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [],
'DEFAULT_PERMISSION_CLASSES': [],
}
The error which I got is:
ImproperlyConfigured("settings.DATABASES is improperly configured. "django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
Is there any minimal settings which does not include django.contrib.contenttypes
and django.contrib.auth
?
The actual cause of the problem is that DRF trys to add a
user
attribute to therequest
. Briefly mentioned in the documentation, the mechanism is as follows:So it needed the
django.contrib.auth
application to run correctly, consequentlydjango.contrib.auth
requires a working configuration of Database to be able to perform.The solution to this problem is to set the settings
UNAUTHENTICATED_USER
property toNone
.Configuration will be like this after the changes:
[not tested] maybe you could use a dummy backend. I see there's one from django:
You don't have any option.
DATABASES
dict should be insettings.py
. You can use this:If you are really forced to use a database but you don't want to, you can use
:memory:
with the SQLite backend, like this:This uses an in-memory database, so that your filesystem won't be touched.
Because memory is volatile, you might need to run migrations automatically every time your web app starts.