简体   繁体   English

Flask 应用程序:无法为端点“post_to_db”构建 url

[英]Flask App: Could not build url for endpoint 'post_to_db'

I am new to making Flask apps, so I might be missing something obvious.我是制作 Flask 应用程序的新手,所以我可能会遗漏一些明显的东西。 What I am trying to do is take a value from a slider and increment a value in my postgresql table by the slider value and then increment another value in my postgresql table by 1. I am getting the error: What I am trying to do is take a value from a slider and increment a value in my postgresql table by the slider value and then increment another value in my postgresql table by 1. I am getting the error:

werkzeug.routing.BuildError: Could not build url for endpoint 'post_to_db'. Did you mean 'static' instead?

Here is my html:这是我的 html:

<form method="POST" action="{{ url_for('post_to_db') }}">
    <input class='slider'id="mydata" name="mydata" type="range" min="0" max="10" value="5" step='1'>
    <div id='button-dock'>
        <button type='submit'>"Show Me Another"</button>
    </div>
</form>

Here is my python:这是我的 python:

class Dataentry(db.Model):
    __tablename__ = "shoe-ratings"

    id = db.Column(db.Integer, primary_key=True)
    total_score = db.Column(db.Integer)
    num_ratings = db.Column(db.Integer)

    def __init__(self, total_score, num_ratings):
        self.total_score = total_score
        self.num_ratings = num_ratings

    def __repr__(self):
        return '<id {}>'.format(self.id)

    def serialize(self):
        return {
            'id': self.id,
            'total_score': self.total_score,
            'num_ratings': self.num_ratings
        }

@app.route("/virgil_io/submit/", methods=["POST"])
def post_to_db():

    score = request.form['mydata']

    shoe = Dataentry.query.first()
    shoe.total_score = shoe.c.total_score + score
    shoe.num_ratings = shoe.c.num_ratings + 1

    try:
        db.session.add(shoe)
        db.session.commit()
    except Exception as e:
        print("\n FAILED entry\n")
        print(e)
        sys.stdout.flush()
    return "Success"

@APP.route('/virgil_io/')
def index():
    return flask.render_template('index.html')

Here is my directory:这是我的目录:

在此处输入图像描述

Things I've tried:我尝试过的事情:

  • Creating a /submit folder in my directory.在我的目录中创建一个 /submit 文件夹。
  • Taking out methods=["POST"]取出methods=["POST"]

Any ideas?有任何想法吗? Thanks!谢谢!

As always, it was a stupid little thing.一如既往,这是一件愚蠢的小事。 My app was named APP , but I was using app for this method.我的应用程序被命名为APP ,但我使用的是这种方法的app

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flask BuildError - 无法为端点构建 URL - Flask BuildError - Could not build URL for endpoint 无法为端点构建 url - Could not build url for endpoint Flask python - werkzeug.routing.BuildError: 无法为端点构建 url - Flask python - werkzeug.routing.BuildError: Could not build url for endpoint 添加装饰器后,烧瓶抛出“无法为端点“索引”构建URL” - Flask throwing “Could not build url for endpoint 'index'” after adding a decorator Flask app.route(“ / authors / add”按钮无法为端点“ / authors / add”构建URL。您是说“ authors”吗? - Flask app.route(“/authors/add” button Could not build url for endpoint '/authors/add'. Did you mean 'authors' instead? 关于Python Flask“ BuildError:无法为端点&#39;index&#39;建立URL。 您是说&#39;main.index&#39;吗?” - About Python Flask “BuildError: Could not build url for endpoint 'index'. Did you mean 'main.index' instead?” Flask-SQLAlchemy 分页错误:无法为具有值 ['page'] 的端点构建 url - Flask-SQLAlchemy pagination error: Could not build url for endpoint with values ['page'] werkzeug.routing.BuildError:无法为端点“配置文件”构建 url。 你指的是“家”吗? 与 Flask - Python - werkzeug.routing.BuildError: Could not build url for endpoint 'profile'. Did you mean 'home' instead? with Flask - Python Flask 端点未构建:无法为端点“edittenant”构建 url。 您是否忘记指定值 - Flask End Point Not Building: Could not build url for endpoint 'edittenant'. Did you forget to specify values Flask-Admin和Blueprint工厂模式正在给出werkzeug.routing.BuildError:无法为端点&#39;admin.static&#39;构建url - Flask-Admin and Blueprint factory pattern is giving werkzeug.routing.BuildError: Could not build url for endpoint 'admin.static'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM