I am trying to get data from my react front end submitted as multipart form data into flask. However, every time I try to print data to the console, it comes up as "None;" I've tried printing the entire request.form and it's an empty ImmutableMultiDict.
So far I've tried
- Setting a content type header on the axios request stating it is multipart/form-data
- Making sure the user object is populated/not falsey in the first place
- Ensuring all fields have a name attached to them
- Switching from React Bootstrap to basic html forms and inputs (made no difference)
Any ideas on what's wrong, or where to go from here, are much appreciated.
//FLASK CHECK @app.route('/user/sign_up', methods=['GET', 'POST']) def api_sign_up(): try: if request.method == 'POST': data = request.form print(data.get('username')) ) return "success" except Exception as e: print(e) return str(e) //CONSOLIDATED REACT HANDLESUBMIT FUNCTION const handleSubmit = (e) => { const user = { email: email, full_name: full_name, username: username, password: password, biography: biography, roles: role, profile_picture: profile_picture, availability: dates.map((date) => { return date.getMonth() + 1 + "/" + date.getDate() + "/" + date.getFullYear(); }), us_phone_number: us_phone_number } setSubmitted(true); axios_instance.post('SIGN_UP_ROUTE', user) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); }); }``` https://stackoverflow.com/questions/66467776/flasks-request-form-returning-none-for-all-attributes-with-multipart-form-data March 04, 2021 at 10:34AM
没有评论:
发表评论