python - Issues sending and receiving a GET request using Flask -


i'm having issues correctly sending , receiving variable request. cannot find information online either. html form below, can see i'm sending value of 'question' i'm receiving 'topic' radio button in form (though code is not below).

i want send 'topic' using post use 'question'. i'm aware form method post though i'm not sure how cater both post , get.

html form:

<form method="post" action="{{ url_for('topic', question=1) }}"> 

my second issue i'm unsure how receive 'topic' , 'question' form. i've managed receive 'topic' seen below i'm not quite sure how receive 'question'. preferably better url so:

www.website.com/topic/sometopic?question=1

for code below, found online request.args[] used receiving requests though i'm not sure if correct.

flask:

@app.route('/topic/<topic>', methods=['post', 'get']) def questions(topic):     question = request.args['questions']     return render_template('page.html') 

the question is

  1. how send 2 variables form using , post different variables @ same time.
  2. how go receiving both variables?

the short answer question can't send both , post using same form.

but if want url specified:

www.website.com/topic/sometopic?question=1 

then you're there. first need know name of topic have specify in call url_for() questions url.

<form method="get" action="{{ url_for('questions', topic_name="cars") }}"> # url generated www.website.com/topic/cars 

flask

# note changed variable name here can see how # related what's passed url_for @app.route('/topic/<topic_name>') def questions(topic_name):     question = request.args['question']     return render_template('page.html') 

now when submit form, input sent get, asumming have input field name question you'll able value of field.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -