Sijax obj_响应不警告或修改Flask中的任何内容?

2024-10-16 20:42:48 发布

您现在位置:Python中文网/ 问答频道 /正文

My form submits data through a sijax request and to acknowledge the submission I use obj_response. I tried both obj_response.alert() as well as obj_response.html() but nothing worked

My code:

from flask import Flask, render_template, request, flash, g, redirect, url_for
from flask_sqlalchemy import SQLAlchemy
import flask_sijax
import os
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///Login.sqlite3"
path = os.path.join('.', os.path.dirname(__file__), 'static/js/sijax1/')
app.secret_key = 'super secret key'
app.config['SESSION_TYPE'] = 'filesystem'
app.config['SIJAX_STATIC_PATH'] = path
app.config['SIJAX_JSON_URI'] = 'static/js/sijax/json2.js'

db = SQLAlchemy(app)
flask_sijax.Sijax(app)


class Signup(db.Model):
    ID = db.Column("ID", db.String(10), primary_key=True)
    Fname = db.Column(db.String(20))
    LName = db.Column(db.String(20))
    Password = db.Column(db.String(20))


    def __init__(self, id, fname, lname, password):
        self.ID = id
        self.Fname = fname
        self.LName = lname
        self.Password = password


@flask_sijax.route(app, '/signup')
def home():
    def caller(obj_response, values):
        newuser = Signup(values['ID'], values['fname'], values['lname'], values['Password'])
        db.session.add(newuser)
        db.session.commit()
        obj_response.html("#result", "Successfully signed up")


    if g.sijax.is_sijax_request:
        g.sijax.register_callback('call', caller)
        return g.sijax.process_request()
    return render_template("first.html")


@app.route("/success", methods=['POST', 'GET'])
def success():

    records = db.session.query(Signup).all()
    return render_template("second.html", records=records)

if __name__ == "__main__":
    db.create_all()
    app.run(host="127.0.0.1", port=2908, debug=True, threaded=True)

My HTML file

^{pr2}$

Tags: pathimportselfidconfigobjappflask