How to call python functions from a flask instance and return values

here is what I need to do: I have a python app with a Flask instance running on machine A and another python app running on machine B. The code on machine B shall call a url post request with a json like this: response=requests.post(url="http://127.0.0.1:5000/get_remote_data", json={"my_key":"my_value"}) The problem is that I don’t know how to… Read More How to call python functions from a flask instance and return values

Flask Invalid Status Argument when requesting from API

I’m having an issue where when I try to GET all restaurants through my api route. Using http://localhost:5000/restaurant/ @restaurant.route(‘/’, methods=[‘GET’]) def get_all_restaurants(): """Get all restaurants""" try: restaurants = list(restaurants_collection.find()) except Exception as e: return make_response({‘message’: f’something went wrong {e}’}, 400) return {‘status’: 200} , jsonify(restaurants) I’m running into this error. Traceback (most recent call last):… Read More Flask Invalid Status Argument when requesting from API

How to resolve TypeError: 'Request' object is not callable Error in Flask?

I am trying to learn Flask. and here I am facing an issue. I have created a route ( /register ) in my Flask app. and I am trying to trigger this using Postman. But I am getting this Error: TypeError: ‘ImmutableMultiDict’ object is not callable Here is my code for /register route. @app.route(‘/register’, methods=[‘POST’])… Read More How to resolve TypeError: 'Request' object is not callable Error in Flask?

Pass a Python + Flask variable in an HTML attribute

(Novice btw) I’m using Python + Flask I have Python variable I want to place in as a substitute for a value=" " My attempt: value="{{ variable }}" didn’t work <form> <textarea value="{{ result }}"></textarea> </form> render_template("home.html", result=result) Any guidance appreciated. >Solution : Try <textarea>{{ result }}</textarea> instead of <textarea value="{{ result }}"></textarea>

Bad Request 400 when uploading file to Flask

I have a Flask server that looks like this: import flask, os, werkzeug.utils UPLOAD_FOLDER = "files/" ALLOWED_EXTENSIONS = {"txt"} def isFileAllowed(file): return str("." in file and file.rsplit(".", 1)[1].lower() in ALLOWED_EXTENSIONS) app = flask.Flask(__name__) app.config["UPLOAD_DIR"] = UPLOAD_FOLDER @app.route("/log_receiver", methods = ["POST", "GET"]) def log_receiver(): if flask.request.method == "POST": file = flask.request.files["file"] if file and isFileAllowed(file): filename… Read More Bad Request 400 when uploading file to Flask

jinja2.exceptions.TemplateSyntaxError: expected token ':', got '}' in html

i’m trying to make an if into my code html with flask: {% if {{ role }} = 1 %} <div id="cabecera"> <header class="py-3 mb-4 border-bottom"> <div class="container d-flex flex-wrap justify-content-center"> <a href="/home" class="d-flex align-items-center mb-3 mb-lg-0 me-lg-auto text-dark text-decoration-none"> i send {{ role }} from the login but when i execute the code, it… Read More jinja2.exceptions.TemplateSyntaxError: expected token ':', got '}' in html

How to pass json array to html page via flask render_template

I’m working on attendance monitoring, where each student attendance status will be captured via API response in flask and need to show the response in dashboard format. Below the sample response we get – [ {"StudentName":"Name1", "Status":"Present"}, {"StudentName":"Name2", "Status":"Absent"} ] I’m able to capture individual student details using array[0] and passing only 1 value to… Read More How to pass json array to html page via flask render_template

Unable to send sms on whatapp throguht route

bascially i am making a route in which i have connect my api of whatapp when i send a number in my json response thought software this route should send me a whatapp message on that number @app.route(‘/v1.1/userRegistor’, methods=[‘POST’,’GET’]) def get_user(): data = request.get_json() numbers=data[‘numbers’] api_url = (‘https://app.simplywhatsapp.com/api/send.php?number=numbers&type=text&message=test%20message&instance_id=634CF8BECCB26&access_token=78495efca3672167f9ed88cb93acd2e1&#8217;) r = requests.get(api_url) return r.json() this is… Read More Unable to send sms on whatapp throguht route

Using parameters in Flask url

Is it possible to put PATH like this text/text.txt into URL parameter in Flask ? It is important that it contains PATH with slash and dot. @app.route(‘/<path>’) def getPath(path): return path >Solution : If you use variable rules with the prefix path your requirements should be met. @app.route(‘/<path:filename>’) def getPath(filename): return filename