小编Sha*_*Sid的帖子

为什么我得到 <built-in method title of str object at 0x7fb554f9f238> 而不是 value ?

我试图从 book_title 检索 title 属性,但我得到了<built-in method title of str object at 0x7fb554f9f238>。我已将 book_title 作为参数传递给路由簿,并在 booktitle.html 中分配了 book_title 的相应值

这是我的路线

@app.route('/search/<title>/',methods=['GET','POST'])
def btitle(title):
    book_title = db.execute("SELECT title,author,isbn from books WHERE (title LIKE :title)",params={"title":title}).fetchall()
    if request.method == 'GET':
        book_title = db.execute("SELECT title,author,isbn from books WHERE (title LIKE :title)",params={"title":title}).fetchall()
        if book_title:
            return render_template("booktitle.html",book_title=book_title)
        else:
            return render_template("error.html")
    else:
        book_title = db.execute("SELECT title,author,isbn from books WHERE (title LIKE :title)",params={"title":title}).fetchall()
        if book_title:
            return redirect(url_for("book",book_title=book_title))



@app.route('/books/<book_title>/',methods=['GET','POST'])
def book(book_title):
    if request.method == 'GET':
        return render_template("individualbook.html",book_title=book_title)
Run Code Online (Sandbox Code Playgroud)

而且,这些是用于 …

python jinja2 flask

5
推荐指数
1
解决办法
3776
查看次数

类型错误:尝试在会话中存储用户 ID 时,“ResultProxy”对象不支持索引

在我的Signedup路线中,我试图将用户 ID 存储在会话中并自动登录用户,但是当我尝试这样做时,我收到此错误:

TypeError: object of type 'ResultProxy' does not support indexing

而且,在我的signin路线中,我试图记住哪个用户已登录,但在这里出现错误:

TypeError: object of type 'ResultProxy' has no len()

signedup 路线 application.py

@app.route("/signedup",methods=["GET","POST"])
def signedup():
    if request.method=="POST":
        password = request.form.get("password")
        hash = pwd_context.encrypt(password)


        name = request.form.get("name")



        if not name:
            return "must provide username"
        elif not password:
            return "must provide password"



        registration = db.execute("INSERT INTO users (username,password) VALUES (:username,:password)",
                    {"username":name,"password":hash})

        if not registration:
            return "pick a different username"


        # Store their ID in session and …
Run Code Online (Sandbox Code Playgroud)

session flask python-3.x flask-sqlalchemy

2
推荐指数
1
解决办法
2632
查看次数

有没有办法从地图上获取特定的键值对?

我目前正在学习有关STL中的地图的信息。我想知道如何从地图上获取特定的键值对。例如,下面地图中的第三个键值对。'C'-> 1

    'A'-> 1
    'B'-> 1
    'C'-> 1
    'D'-> 1
    'E'-> 2

Run Code Online (Sandbox Code Playgroud)

c++ dictionary iterator stl

1
推荐指数
1
解决办法
44
查看次数