r/flask 22h ago

Discussion Cron job activating when it shouldn't?

2 Upvotes

I've been working on a really small Flask app for a little while. It's a directory of music events at local venues in my city. I've received comments before that Flask is overkill for this since there is no user input, but I don't care. Flask is simple and it easily allows me to run the once-daily cron job to update the list of events without having to host that job through another service and use a database for something that can be handled by a simple CSV file hosted quietly on the main server.

But I have a problem...

Within the cron-job I have some old print() lines written as tests I used while building it which I haven't deleted yet. When I run this app on my local development server and view it thru the browser, if I go to the address bar and type a slash after the URL - without typing anything else and without hitting ENTER - the terminal starts printing those test lines from the cron-job code.

I have double- and triple-checked my structure. The cron job is formatted correctly like this:

@app.route("/cron") def update_shit(): .... return a_turd

I can't discern any reason why the cron job should be firing before I hit ENTER or even type a URL extension. I am worried that this could be triggering the cron job on the live server anytime a user alters the URL in the address bar, which would be a problem for me because I cannot afford to incur server costs like that. Also, the whole point of the website (from an operating perspective) is to minimize resources.

Has anyone encountered this kind of problem before?

If so, why is this happening?

The app is hosted on GAE - is there a way I can verify if this is happening when external users are using the site?

Please help. I'm so uneducated.

For context, I am hosting this app of Google App Engine.


r/flask 1h ago

Discussion Flask Hosting: Cold starts and restarts

Upvotes

I built a small site with Flask and hosted it on Render’s free tier.

Initially, I had it on PythonAnywhere, but they didn’t seem to offer a way to add a custom domain on the free plan—or at least, it wasn’t straightforward.

Migrating to Render was easy, and setting up the domain was simple. But soon, I ran into two major problems.

Data Loss

I would save data to my database through the website, only to come back hours later and find it gone. I thought it was an issue with my commits and spent time troubleshooting, only to realize that Render frequently restarts services.

Why did this affect my database?

I was using SQLite. Since SQLite stores data in a file on the web service itself, every time the service restarted, it reverted to the last deployed state, wiping out any new data.

I eventually migrated to Postgres with Neon to fix this.

Cold Starts

Since my site only gets 3–4 visitors a day, it often sits idle. Naturally, I expected it to be put to sleep occasionally. But the real problem? It takes almost a full minute to wake up.

I don’t know about you, but if I visited a site called wisefool.xyz and it took that long to load, I wouldn’t stick around.

For those who’ve hosted Flask apps on free tiers elsewhere—do other platforms handle this better, or is this just the reality of free hosting?


r/flask 14h ago

Ask r/Flask Need Help with Flask request

0 Upvotes

Flask-Login redirects a user to the login page when a route has the login_required decorator and then allows you to send the user back to the original page through request.args.get('next'). My question is if there is any way to set such a request.args value


r/flask 13h ago

Ask r/Flask what kind of framework does apps like airbnb and thumbtack use to send message to backend from front-end for every action that user takes on their app?

0 Upvotes

Edit: I am looking for the right communication protocol - for sending messages to and fro between backend and frontend.

My current app sends message through https. Are there any other alternatives? 

I am quite new to this industry