0

I am currently using Flask and axios. I have a redirect on the Flask side with data that is passed, resulting in my having to put the decorator as /results/<usr>/. When I do a print, the results show up inside my Python cmd. On my front end side using VUE, I have the code block below that I assumed would be able to get the information returned under the /results/<usr> block. However, none of the console.log actually gets logged in my browser. I have tried sending a POSTMAN request but that has failed as well.

I am unsure if I need to provide parameters besides "http://127.0.0.1:5000/results/" under my path variable for the VUE portion. Any advice will be appreciated!

Flask

@app.route('/', methods=["GET", "POST"])
def home():
    if request.method == "GET":
        data = request.get_json()
        return redirect(url_for("getResults", usr = data))

@app.route('/results/<usr>')
def getResults(usr):
    if request.method == "GET":
        return "Please work :<"

VUE

methods:{
        getResponse(){
            const path = "http://127.0.0.1:5000/results/";
            axios.get(path)
            .then((res) => {
                console.log("I am reading this");
                console.log(res.data);
            })
            .catch((err) => {
            console.error(err);
            });
        },
}
Peek0
  • 173
  • 2
  • 9
  • 1
    Your route is defined as `/results/`. You would have to provide a parameter for the `` part in your URL, such as `/results/1`. Otherwise it would probably return a 404 - not found. – Dr4jw3r Aug 04 '22 at 06:05
  • That is what I suspect actually, but in this case how would someone typically send information back? I am sending a form data from the first page to the server, which process and returns a JSON object that I have to read. – Peek0 Aug 04 '22 at 06:31
  • First of all, you have to make sure your requests actually reach your backend. To achieve this, either add a parameter to your URL in the front-end or remove it in the back-end. Which one you choose depends on your requirements. Your front-end code for sending the request and displaying the response looks correct to me. If you want to return JSON from Flask, refer to https://stackoverflow.com/a/13089975/1851102 – Dr4jw3r Aug 04 '22 at 06:46

0 Answers0