PostgreSQL Databases - 02 Connecting your Code

Sdílet
Vložit
  • čas přidán 19. 01. 2023
  • You've built your PostgreSQL database with just two clicks, but how do we access it from your code?
    Publish your work to the Replit Community or tweet about it and tag Replit.
    #replit #replitPostgreSQL
  • Zábava

Komentáře • 2

  • @user-jm5cn2yk7x
    @user-jm5cn2yk7x Před rokem +3

    this actually does not work because my secret URL is an entire link and looks nothing like yours and will not work based on these steps. Really frustrating when code tutorial videos do not actually show accurate examples and leave the learner troubleshooting to figure out what is wrong. This was not helpful at all.

    • @benjohnson5897
      @benjohnson5897 Před 5 měsíci

      At the bottom of your Secrets list there's a section that says "Access secret" with a drop-down next to it. Select the DATABASE_URL, and underneath it shows the lines needed in your code to access that envrionment variable. typically you'll need "import os" at the start of your code, and to access the secret its in the form of my_secret = os.environ['DATABASE_URL'] - so you can then use "my_secret" in your code for the database url, or as he did in the tutorial skip storing it to my_secret and just directly put conn = psycopg2.connect(os.environ['DATABASE_URL'])