django - 如果你不需要数据库引擎,你应该怎么办? [英] django - what should you do if you don't need a database engine?

查看:955
本文介绍了django - 如果你不需要数据库引擎,你应该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您无法在setting.py中设置数据库引擎,则会出现错误。

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

是否有某种方法可以禁用django的数据库部分如果你不需要数据库?

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?

推荐答案

如果你想使用数据库引擎, django的一些功能,例如会话。如果你不需要它们,只需从中间件类中删除它们。

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.

如果您想要使用django应用程序来使用会话或存储一些数据,但不想执行所有复杂的数据库配置,则可以使用sqlite3作为数据库引擎。它不需要任何设置,所有你需要的是指定一个路径,将创建和存储数据库文件。这是:

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.
    }
}

这篇关于django - 如果你不需要数据库引擎,你应该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆