1

I have a Firebase Firestore database connected to a Flutter mobile application. I want to build a web application to manage the users' data and handle new users. I have decided to use Django for my web application, but I have two questions if anyone can help.

First, is it actually reliable to use Django as the framework for this purpose? Second, I was trying to make a connection between Django and my existing DB to just try to call some values but I was getting this error:

google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application.

Here is the code I am using for the connection


db = firestore.Client()

config={
    "apiKey": "******************",
    "authDomain": "*******.firebaseapp.com",
    "projectId": "*******",
    "storageBucket": "*******.appspot.com",
    "messagingSenderId": "*******",
    "appId": "******************",
    "databaseURL": "https://***********.firebaseio.com",
}    
firebase = pyrebase.initialize_app(config)
auth = firebase.auth()
database = firebase.database()

def index(request):
   doc = db.collection('test').document('test1').stream()
   weight= doc['weight']
   
    return render(request, 'index.html', {
        "weight":weight,
    })

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
taha khamis
  • 401
  • 4
  • 22
  • Where does your `firestore` object come from? That doesn't exist in [Pyrebase](https://github.com/thisbejim/Pyrebase), so most likely it comes from another SDK, and you'll need to initialize that. For example, as shown here for the Python Admin SDK in the documentation on [setting up Firebase on your server](https://firebase.google.com/docs/admin/setup#python_1) – Frank van Puffelen Dec 29 '22 at 04:57
  • Read this article https://www.section.io/engineering-education/integrating-firebase-database-in-django/ – Thierno Amadou Sow Dec 29 '22 at 06:05

1 Answers1

1

You're initializing Pyrebase with client-side configuration data. But Pyrebase doesn't have any built-in support for Firestore, so most likely you'e importing that from elsewhere. If your firestore comes from the Admin SDK that Firebase itself supports for use in Python code, you'll need to initialize that SDK too, as shown here in the documentation on setting up Firebase on your server

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Thank you for your time and answer. I tried to follow the process from the documentation but I still got the same error. here is how I initiated the connection and please let me know if I did something wrong ..... cred = credentials.Certificate("./serviceAccountKey.json") firebase_admin.initialize_app(cred) – taha khamis Dec 29 '22 at 15:16
  • The issue was solved by adding this line to the file setting.py os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="./serviceAccountKey.json" – taha khamis Dec 29 '22 at 15:44