Hi, I’m building a website using Python. I’ve linked the Python server to the dev PostgreSQL provided by the app Platform on digital ocean. Everything is working fine, but when I add new records to the dev db I have to redeploy the app to see the new records appearing on the home page. I want the new records to be available without the need for redeploying the app.
This is how my python script looks like:
import psycopg
from urllib.parse import parse_qs
# Create a connection to the SQLite database
def add_post(post_data):
parsed_data = parse_qs(post_data)
con = psycopg.connect("MY CONNECTION STRINGS")
cur = con.cursor()
name = parsed_data.get('name', [''])[0]
date = parsed_data.get('date', [''])[0]
place = parsed_data.get('place', [''])[0]
link = parsed_data.get('link', [''])[0]
category = parsed_data.get('category', [''])[0]
description = parsed_data.get('description', [''][0])
cur.execute("insert into events (poster, category, date, place, media, description)VALUES (%s, %s, %s, %s, %s, %s)", (name, category, date, place, link, description[0]))
con.commit()
con.close()
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi there,
It sounds like your app may be caching the database results, which would explain why you have to redeploy to see new records. When you redeploy, the cache is cleared, and your app queries the database again, pulling in the new records.
To solve this, you’ll need to adjust your application’s logic to query the database for new records dynamically, without relying on the state of the application when it was first deployed. Ensure that each request to your home page triggers a fresh database query or set up a timed cache invalidation strategy.
Check the part of your code that retrieves and displays records on the homepage. It should make a new connection and fetch the latest data each time the page is loaded or refreshed, not just when the app starts. If you’re using any form of caching, review your cache policy to ensure it doesn’t prevent updates from appearing immediately.
Feel free to share more details about your app and I will be happy to advise you further!
Best,
Bobby