我正在尝试将Firebase实时数据库与我的Django Web应用程序一起使用。在正确配置Firebase后,我对如何从我的Django网站将数据编写到Firebase数据库中而不是使用Sqlite或者Postgres感到困惑。
在 settings.py
文件下,我需要将我的引擎设置为Firebase吗?我完全感到困惑。我不想使用常规的ORM,如Sqlite、Postgres等。我希望我的应用程序使用Firebase。
还有其他关于Firebase需要了解的事情吗?
settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
pyrebase_settings 文件
import pyrebase
config = {
"apiKey": "my_api_key_is_here",
"authDomain": "my_auth_domain_is_here",
"databaseURL": "my_firebase_database_url_is_here",
"projectId": "my_firebase_project_id_is_here",
"storageBucket": "my_firebase_storageBucket_is_here",
"serviceAccount": "my_serviceAccount.json_file_path_is_here",
"messagingSenderId": "messagingSenderId_is_here"
}
# initialize app with config
firebase = pyrebase.initialize_app(config)
# authenticate a user
auth = firebase.auth()
user = auth.sign_in_with_email_and_password("email@usedforauthentication.com", "FstrongPasswordHere")
db = firebase.database()