Flask form not validating on submit

I’m trying to make a form that looks like an exam page. I have a checkbox and a submit button, the submit button when clicked does not do anything. The HTML code in exam.html {% extends ‘layout.html’ %} {% block content %} <h3 class="pt-5 p-4">exam page</h3> <div class="form"> <fieldset class="form-group"> <form method="POST" action="/" class="m-3"> {{… Read More Flask form not validating on submit

How to filtering out json object contain certain key in FLASK?

I have a JSON file : { "id":"xyz", "word":"this is word", "formats":[ { "formatId":"xz99", "pengeluaran":"pengeluaran_1", }, { "formatId":"xy100", "pengeluaran":"pengeluaran_2", }, { "ukuran":451563, "formatId":"xy101", "pengeluaran":"pengeluaran_1", }, } in my python.py files, i want to filtering out the JSON object only contain "ukuran" as a key , my expected to getting result like this : { "id":"xyz",… Read More How to filtering out json object contain certain key in FLASK?

Trying to pass a nested list with JSON to JS with Flask

The problem is I’m passing my argument to the Javascript like this: link. The variable "chatlist" is the problem. The value of that variable is [[{"user": "lol"}, {"msg": "lol has created this chat."}], [{"user": "lol"}, {"msg": "lol"}]] But when I try to access that variable through this code: link, it ends up looking like [[{&#34;user&#34;:… Read More Trying to pass a nested list with JSON to JS with Flask

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&quot;, 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