23👍
The actual cause of the problem is that DRF trys to add a user
attribute to the request
. Briefly mentioned in the documentation, the mechanism is as follows:
How authentication is determined
If no class authenticates,
request.user
will be set to an instance of
django.contrib.auth.models.AnonymousUser
So it needed the django.contrib.auth
application to run correctly, consequently django.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 to None
.
Configuration will be like this after the changes:
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [],
'DEFAULT_PERMISSION_CLASSES': [],
'UNAUTHENTICATED_USER': None,
}
21👍
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:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
}
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.
- [Django]-How do I render jinja2 output to a file in Python instead of a Browser
- [Django]-Install mod_wsgi on Ubuntu with Python 3.6, Apache 2.4, and Django 1.11
- [Django]-Consolidating multiple post_save signals with one receiver
2👍
You don’t have any option. DATABASES
dict should be in settings.py
. You can use this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
- [Django]-Navigation in django
- [Django]-How can I temporarily disable a foreign key constraint in MySQL?
- [Django]-Multiple files upload using same input name in django
-1👍
[not tested] maybe you could use a dummy backend. I see there’s one from django:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.dummy',
}
}
- [Django]-How can I programmatically obtain the max_length of a Django model field?
- [Django]-Django Tastypie Advanced Filtering: How to do complex lookups with Q objects
- [Django]-Django – deterministic=True requires SQLite 3.8.3 or higher upon running python manage.py runserver