'Struggling with flask request in pycharm community 404 bad request
My terminal returns
None /calculate_salary HTTP/0.9 HTTPStatus.BAD_REQUEST - but in webpage it says 404 not found, the requested url was not found on the server if you entered the url manually check your spelling and try again."
import flask
from flask import *
from flask import render_template
from utilities import cc
app = Flask(__name__)
@app.route('/helicopter')
def hello_world():
return 'Heli, World!'
@app.route('/')
def salary_form_one():
return render_template('index.html')
# This is where problem starts
@app.route('/calculate_salary,', methods=['POST'])
def calculate_salary():
if request.method == 'POST':
# This variable named profession is = to the input for the form qustion named profession
profession = int(request.form['profession'])
number_of_expereince_years = int(request.form['experince'])
languages = request.form['languages']
user_coding_languages = languages.split()
design_tools = request.form['designTools']
users_design_tools = design_tools.split()
dob = request.form['dob']
full_name = request.form['FullName']
age = request.form['age']
country = request.form['country']
state = request.form['state']
number_of_education_years = request.form['educationYears']
if int(profession) == 1:
is_designer = False
else:
is_developer = False
result_message = cc.calculate_expected_salarys(users_design_tools, state, languages, is_developer,
is_designer, dob, age, state)
return flask.render_template("result.html", message=result_message)
else:
return 'please submit a post request'
My guess is I didn't assign the route, but I don't know for sure.
Solution 1:[1]
Note that you can get a 404 if you get the HTTP method wrong in the request - your handler says that it only handles POST requests (methods=["POST"]). So, if you're making, say a GET request, you'll get a 404. This also means that your if/else checking the request method is redundant.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ndc85430 |
