Подключение HTML-формы к базе данных FirebasePython

Программы на Python
Anonymous
Подключение HTML-формы к базе данных Firebase

Сообщение Anonymous »


Есть аналогичный вопрос, но он был задан почти десять лет назад.
У меня есть HTML-форма, которая заполняется и распечатывается console.log. У меня есть база данных Firebase. У меня просто так много проблем, когда я пытаюсь их подключить. Я знаю, что база данных Firebase настроена правильно, поскольку мне удалось подключиться и отправить к ней жестко запрограммированные данные с помощью скрипта Python

Код: Выделить всё





Form





Form

First Name:



Last Name:



Email:



Phone:



Submit




I've tried many different ways to connect this via JS but I just cant seem to work it out

Код: Выделить всё

var firebaseConfig = {
apiKey: "APIKEY",
authDomain: "AUTHDOMAIN",
databaseURL: "DATABASEURL",
projectId: "PROJECTID",
storageBucket: "STORAGEBUCKET",
messagingSenderId: "MESSAGINGSENDERID",
appId: "APPID"

};

firebase.initializeApp(firebaseConfig);

var db = firebase.database();

document.getElementById('contactForm').addEventListener('submit', function(e) {
e.preventDefault();
print("Test")
var first = document.getElementById('first').value;
var last = document.getElementById('last').value;
var email = document.getElementById('email').value;
var phone = document.getElementById('phone').value;
print("Test2")
db.ref('users').push({
first : first,
last : last,
email : email,
phone : phone,
})
print("Test3")
.then(() => {
print("Test4")
console.log("Data submitted successfully.");
document.getElementById('contactForm').reset();
})
.catch((error) => {
console.error("Error submitting data: ", error);
});
});

from flask import Flask, request

app = Flask(__name__)

@app.route('/submit', methods=['POST'])
def submit_form():
data = request.form

print(data)
return 'Form submitted successfully'

if __name__ == '__main__':
app.run(debug=True)
I'm completely lost at this point and have absolute no clue. When I try to import

Код: Выделить всё

import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";
This seems to break for whatever reason console.log but if I don't firebase is undefined.
I need help. Please


Источник: https://stackoverflow.com/questions/781 ... e-database

Вернуться в «Python»