Alex Rivera | Logout

django - what should you do if you don't need a database engine?

Asked 2011-02-05T19:19:44.627
14

If you fail to set a database engine in setting.py you get an error.

Is there some way to disable the database portion of django for a specific site if you don't have a need for a database?

Edit
Report

2 Answers

11

You are required to use a database engine if you want to use some features of django, like sessions, for example. If you do not need those, just remove them from middleware classes.

If you want to use sessions or store some data using django apps, but do not want to do all the complicated database configurations, you can use sqlite3 as your database engine. It does not require any setup, all you need is to specify a path, where database file will be created and stored. Thats it:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '/var/www/mysite/sqlite.db',                      # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}
answered 2011-02-05T19:26:17.170
1

You don't need to do anything. I don't get an error when I don't define a backend.

  1. django-admin.py startproject myproject
  2. open urls.py and map a url to a view.
  3. run the dev server and visit your page.

Bam, django without a database.

answered 2011-02-05T19:32:44.073

Your Answer