0

All I want to do is get context_answers and treatment_answers from my web user inputs and bring it on the Flask. (I am very new to this, sorry that I am a vague about what I am doing)

`context_answers = {"a":[1], "b":[2], "c":[3], "d":[4]}
treatment_answers = {"y":[10]}`    

I was able to get context_answers doing following:

`methods: {
      handleSubmit() {    
        axios.post("/submit_survey", this.context_answers)
      }
    }`

and on the Flask

`@app.route("/submit_survey", methods=["POST"])
def submit_survey():
    context = request.get_json(force=True)
    context_df = pd.DataFrame.from_dict(context)`

But how do you get this.treatments_answers in the same axios post method? and in the submit_survey?

I want to create a data frame that has following:

a b c d y 1 2 3 4 10

Thank you so much!

1
  • It's unclear what you're asking. Perhaps show an example of each piece of data (ie context_answers and treatments_answers) and what you'd like the received data to look like in your Flask app Commented Sep 10, 2018 at 3:53

1 Answer 1

1

If do you want past many params you can do this:

methods: {
  handleSubmit() {    
    axios.post("/submit_survey", {context_answers: this.context_answers, 
                                                         treatments_answers: this.treatments_answers})
  .then( 
     (response) => { console.log(response) },
     (error) => { console.log(error) }
   )
  }
}

or try this:

 methods: {
      handleSubmit() {    
        axios.post("/submit_survey", {context_answers: this.context_answers, 
                                                             treatments_answers: this.treatments_answers})
      .then(response => { 
         console.log(response)
      })
      .catch(error => {
         console.log(error)
      });
    }
Sign up to request clarification or add additional context in comments.

18 Comments

Thank you David. Then how do I request later? I know it is super basic.
I mean when I had just one context_answer, I used context = request.get_json(force=True) to extract it and convert it into pandas data frame. So now how do I save the treatment now?
in theory you should capture the axion in a variable just like this: const response = await axios.post( ... then make a console.log of response and tell me what you see
Promise {<pending>} __proto__ : Promise catch : ƒ catch() arguments : (...)
I edited my answer, look how the method handleSubmit was, make a console.log of response again and tell me what you see
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.