在Pycharm社区中与烧瓶请求斗争404不良要求

发布于 2025-01-30 19:20:04 字数 1738 浏览 3 评论 0原文

我的航站楼返回 none/carculate_salary http/0.9 httpstatus.bad_request - 但是在网页中找不到404,如果您手动手动输入URL,请在服务器上找到所需的URL,然后再检查您的拼写,然后重新尝试一下。

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 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

握住我的手 2025-02-06 19:20:04

请注意,如果您在请求中获得HTTP方法错误,则可以获得404-您的处理程序说,它仅处理post requests(methods = [“ post”]) 。因此,如果您要做的,请说get请求,您将获得404。这也意味着您的/else检查检查请求方法是多余的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文