Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在mysql中使用hashtag查询字符串_Python_Mysql_Sql_Flask - Fatal编程技术网

Python 如何在mysql中使用hashtag查询字符串

Python 如何在mysql中使用hashtag查询字符串,python,mysql,sql,flask,Python,Mysql,Sql,Flask,我想将书名作为参数传递,并获取对该书的推荐 @app.route('/book_details/<book_title>') def book_details(book_title): cur = mysql.connection.cursor() title = book_title.replace("'", "\\'") title = title.replace("&", "\

我想将书名作为参数传递,并获取对该书的推荐

@app.route('/book_details/<book_title>')
def book_details(book_title):
    cur = mysql.connection.cursor()
    title = book_title.replace("'", "\\'")
    title = title.replace("&", "\\&")
    title = title.replace("#", "\\#")
    resultValue = cur.execute(f"SELECT * FROM `books` WHERE title = '{title}' LIMIT 1")
    if resultValue > 0:
        rec_book_list = output_recommendations(book_title)
        book = cur.fetchall()
        return render_template('testDetails.html', book = book, book_list = rec_book_list)
    return 'No book'
这适用于带有单引号和符号的书名,但如果书名包含hashtag,则不起作用。如果标题中有错误,函数将返回“No book”


如何查询其中包含的字符串?

我将删除所有转义代码,并让连接器执行:cur.executeSELECT*从“其中title=%s LIMIT 1,title,`”一书中。尝试了此操作。适用于除hashtag之外的所有特殊字符我找到了解决方案。和传递hashtag和其他特殊字符不同,传递字符的URL编码是有效的