flask get selected value from dropdown

you might need GET method too: Thanks for contributing an answer to Stack Overflow! Getting value from select tag using flask, Speeding software innovation with low-code/no-code tools, Tips and tricks for succeeding as a developer emigrating to Japan (Ep. Auto reloading python Flask app upon code changes. Been looking for someone to explain this so that I could understand it properly. Is `0.0.0.0/1` a valid IP address? I am trying to get the value from a dropdown menu which consists of numbers. So, if you submit your forms via POST, use request.form.get (). This answer delivers. How can I remove a key from a Python dictionary? How to dare to whistle or to hum in public? Sorry in advance if my formatting is off for the post (also new to Stack Overflow). Thanks for contributing an answer to Stack Overflow! What do you do in order to drag out lectures? Can we prosecute a person who confesses but there is no hard evidence? Then I want to compare the numbers with a value and display a text based on the comparison. Connect and share knowledge within a single location that is structured and easy to search. Can we prosecute a person who confesses but there is no hard evidence? Are softmax outputs of classifiers true probabilities? How can I randomly select an item from a list? . Why is it valid to say but not ? In this tutorial you will learn laravel dynamic dependent dropdown using ajax. Connect and share knowledge within a single location that is structured and easy to search. What is the difference between Python's list methods append and extend? However at the moment I can't even seem to get the POST of the form to work and am at a complete loss. Was J.R.R. I'm completely new to flask, and really am completely lost with how to approach this. Browse other questions tagged, Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide. Method 1: Using the value property: The value of the selected element can be found by using the value property on the selected element that defines the list. I also want to use the value selected in drop down menu in other places as well. @ Mert Celik I tried it again after you edited, but still I am getting the same error Please help me resolve this issue. @MaredpallyJalebi i edited it, now it should works. To subscribe to this RSS feed, copy and paste this URL into your RSS reader. It's hard to know for certain from what you've provided, but I believe you need to add method="POST" to your

element. Site design / logo 2022 Stack Exchange Inc; user contributions licensed under CC BY-SA. Making statements based on opinion; back them up with references or personal experience. Which one of these transformer RMS equations is correct? I added the 'with open ('newTest.csv)' code seen in the edit of the OP to your answer, replacing the ' your code ' however after submitting the form the file still doesn't appear. from flask import render_template from app import app from pymongo import mongoclient @app.route ('/') @app.route ('/index') def index (): user = {'name': 'bob'} client = mongoclient () client = mongoclient ('mongodb://localhost:27017/') db = client.test_database db = client ['test-database'] collection = db.test_collection posts = db.posts Use a list of values to select rows from a Pandas dataframe. Ask Question Asked 1 year, 7 months . I'm very new to Flask and web development and am having some trouble with generating a list from a mongdb query and passing that through to the html template to be in a dropdown menu in Flask. Why do many officials in Russia and Ukraine often prefer to speak of "the Russian Federation" rather than more simply "Russia"? Does picking feats from a multiclass archetype work the same way as if they were from the "Other" section? How are interfaces used and work in the Bitcoin Core? Basic question: Is it safe to connect the ground (or minus) of two different (types) of power sources, Step size of InterpolatingFunction returned from NDSolve using FEM. Active 2 years, 7 months ago. Not the answer you're looking for? How can I get the named parameters from a URL using Flask? @ Mert Celik Unfortunately your solution is also not working I am getting the following error : Internal Server Error The server encountered an internal error and was unable to complete your request. Gate resistor necessary and value calculation. Why do many officials in Russia and Ukraine often prefer to speak of "the Russian Federation" rather than more simply "Russia"? I want to be able to serve a static html file (located in static/ {platform}/graph.html) within an iframe based on the value ( {platform}) selected from a drop down menu. Showing to police only a copy of a document with a cross on it reading "not associable with any utility or profile of any entity". You are making a pretty simple error. Thanks for contributing an answer to Stack Overflow! I changed the return to "hello world" again and search the webpage for it after submitting but it wasn't found. Jquery's just a collection of wrappers and shims to the core HTML5 Web API. How to connect the usage of the path integral in QFT to the usage in Quantum Mechanics? How can I set the default value for an HTML element? I have tried request.form['comp_select'] which returns a Bad Request. Shiseido Future Solution LX As written in the docs, Okay I've modified it but still nothing appears to happen on the webpage. To access parameters submitted in the URL (?key=value) you can use the args attribute. Start a research project with a student in my class. if request.form['submit'] == 'myselect': choice = x sub_name_list = [q['sub_server'] for q in posts.find({'type': choice})] return render_template("index.html", title='Database selector', user='Bob', server_list=name_list, sub_server_list=sub_name_list),