flask

Is it possible not to use Flask decorators?

Is it possible not to use Flask decorators? Question: I don’t know why, but I don’t like decorators. Can I use def load_user(): if "user_id" in session: g.user = db.session.get(session["user_id"]) app.before_request(load_user) instead of @app.before_request def load_user(): if "user_id" in session: g.user = db.session.get(session["user_id"]) ? Asked By: Dante || Source Answers: A decorator returns a new …

Total answers: 1

flask and Jinja2 control structure doesn't work with render_template.format but works when passing the variable directly

flask and Jinja2 control structure doesn't work with render_template.format but works when passing the variable directly Question: Here is a MRE. templates/index.html: <!DOCTYPE html> <html> <head> <title>Flask App</title> </head> <body> {{test}} {% if test %}lol{% endif %} </body> </html> my_test.py: from flask import Flask, render_template app = Flask(__name__) @app.route("/") def index(): return render_template("index.html", test=True) if …

Total answers: 1

Running Flask App with GUI after boot on Raspberry PI

Running Flask App with GUI after boot on Raspberry PI Question: I’m trying to get a Flask App with a GUI with Tkinter to run on a Raspberry Pi after boot but I can’t seem to get it working. I’ve tried to make it run on boot by putting an sh script inside /etc/init.d/ with …

Total answers: 2

My HTML is not sending the POST method to the flask app function

My HTML is not sending the POST method to the flask app function Question: What’s happening: I have an HTML code that is sending a POST request to the flask code. It’s for a Login page. (I’m using SQLite3 and Flask.) The HTML code: <div class="col"> <div class="login-box"> <h2>Register</h2> <form method="post" action="{{ url_for(‘register_post’) }}"> <div …

Total answers: 1

How to reboot a WSGI application

How to reboot a WSGI application Question: There are a lot of implementation for the WSGI specification, like mod_wsgi and Phusion Passenger. Now I have bought a shared Python host which uses Phusion Passenger. AFAIK there is no standard for how to reboot a WSGI application, so each implementation has its own way. For example …

Total answers: 1

How can I solve a "500 Internal Server Error" when importing modules in __init__.py?

How can I solve a "500 Internal Server Error" when importing modules in __init__.py? Question: I use Flask for the first time. The following __init__.py is working fine : Python v3.10.6 #!/usr/bin/env python3 from flask import Flask, render_template, request app = Flask(__name__) @app.route(‘/testurl’) def testurl(): return render_template(‘index.html’) @app.route(‘/from_client’, methods=[‘POST’]) def from_client(): request_data = request.get_json() return …

Total answers: 2

Can't write to file in Google Cloud

Can't write to file in Google Cloud Question: Currently, I have an SQL Database that I wish to edit locally. This is for a flask app made in python 3, using sqlite3. con = sqlite3.connect(‘Database/accounts.db’) cur = con.cursor() cur.execute(f"INSERT INTO Requests (Type, Argument, Priority, Time) VALUES (‘{a}’,'{b}’,{c},'{d}’)") con.commit() Except I keep getting the error: attempt …

Total answers: 2

Unable to stream API response in Flask application on Google Cloud application

Unable to stream API response in Flask application on Google Cloud application Question: I’m developing a little testing website using the OpenAI API. I’m trying to stream GPT’s response, just like how it’s done on https://chat.openai.com/chat. This works just fine when running my Flask application on a local development server, but when I deploy this …

Total answers: 1

Receiving 'None' from request.form.get when called flask route via XMLHttpRequest

Receiving 'None' from request.form.get when called flask route via XMLHttpRequest Question: I am new to flask and pyhton. I searched many blogs but could not find my use case. I have created a form in HTML. there are two buttons. If the User clicks the First button, data from the HTML form should be passed …

Total answers: 1

How to test the python backend of a flask application?

How to test the python backend of a flask application? Question: I have a draft of a flask application with a html/javascript frontend and a python backend, to which the frontend communicates through the flask API. I want to test the python backend using the API using python only (no javascript etc involved in the …

Total answers: 2