国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

python - 深入理解Flask 第三章代碼運行報錯, 代碼完全正常,為什么報SQL語法錯誤?

瀏覽:117日期:2022-06-29 14:18:28

問題描述

原句posts = Post.query.order_by(Post.publish_date.desc()).paginate(page, 10)

路由這里已經定義 page=1了, 作者不可能寫錯代碼啊, 我設置了utf-8編碼也不行@app.route(’/’)@app.route(’/<int:page>’)def home(page=1): posts = Post.query.order_by(Post.publish_date.desc()).paginate(page, 10) recent, top_tags = sidebar_data() return render_template(’home.html’,posts=posts,recent=recent,top_tags=top_tags )

/Library/Python/2.7/site-packages/sqlalchemy/sql/compiler.py:624: SAWarning: Can’t resolve label reference ’total DESC’; converting to text() (this warning may be suppressed after 10 occurrences) util.ellipses_string(element.element))127.0.0.1 - - [07/Jun/2017 14:44:06] 'GET / HTTP/1.1' 500 -Traceback (most recent call last): File '/Library/Python/2.7/site-packages/flask/app.py', line 1994, in __call__ return self.wsgi_app(environ, start_response) File '/Library/Python/2.7/site-packages/flask/app.py', line 1985, in wsgi_app response = self.handle_exception(e) File '/Library/Python/2.7/site-packages/flask/app.py', line 1540, in handle_exception reraise(exc_type, exc_value, tb) File '/Library/Python/2.7/site-packages/flask/app.py', line 1982, in wsgi_app response = self.full_dispatch_request() File '/Library/Python/2.7/site-packages/flask/app.py', line 1614, in full_dispatch_request rv = self.handle_user_exception(e) File '/Library/Python/2.7/site-packages/flask/app.py', line 1517, in handle_user_exception reraise(exc_type, exc_value, tb) File '/Library/Python/2.7/site-packages/flask/app.py', line 1612, in full_dispatch_request rv = self.dispatch_request() File '/Library/Python/2.7/site-packages/flask/app.py', line 1598, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File '/Users/andy/Desktop/Mastering Flask_Code Bundle/Chapter 3/chapter_3/main.py', line 114, in home top_tags=top_tags File '/Library/Python/2.7/site-packages/flask/templating.py', line 134, in render_template context, ctx.app) File '/Library/Python/2.7/site-packages/flask/templating.py', line 116, in _render rv = template.render(context) File '/Library/Python/2.7/site-packages/jinja2/environment.py', line 1008, in render return self.environment.handle_exception(exc_info, True) File '/Library/Python/2.7/site-packages/jinja2/environment.py', line 780, in handle_exception reraise(exc_type, exc_value, tb) File '/Users/andy/Desktop/Mastering Flask_Code Bundle/Chapter 3/chapter_3/templates/home.html', line 1, in top-level template code {% extends 'base.html' %} File '/Users/andy/Desktop/Mastering Flask_Code Bundle/Chapter 3/chapter_3/templates/base.html', line 45, in top-level template code {% block body %} File '/Users/andy/Desktop/Mastering Flask_Code Bundle/Chapter 3/chapter_3/templates/home.html', line 38, in block 'body' {{ render_pagination(posts, ’home’) }} File '/Library/Python/2.7/site-packages/jinja2/runtime.py', line 551, in _invoke rv = self._func(*arguments) File '/Users/andy/Desktop/Mastering Flask_Code Bundle/Chapter 3/chapter_3/templates/base.html', line 5, in template <a href='http://m.cgvv.com.cn/wenda/{{ url_for(’home’, page=pagination.prev().page) }}' aria-label='Previous'> File '/Library/Python/2.7/site-packages/flask_sqlalchemy/__init__.py', line 338, in prev return self.query.paginate(self.page - 1, self.per_page, error_out) File '/Library/Python/2.7/site-packages/flask_sqlalchemy/__init__.py', line 475, in paginate items = self.limit(per_page).offset((page - 1) * per_page).all() File '/Library/Python/2.7/site-packages/sqlalchemy/orm/query.py', line 2703, in all return list(self) File '/Library/Python/2.7/site-packages/sqlalchemy/orm/query.py', line 2855, in __iter__ return self._execute_and_instances(context) File '/Library/Python/2.7/site-packages/sqlalchemy/orm/query.py', line 2878, in _execute_and_instances result = conn.execute(querycontext.statement, self._params) File '/Library/Python/2.7/site-packages/sqlalchemy/engine/base.py', line 945, in execute return meth(self, multiparams, params) File '/Library/Python/2.7/site-packages/sqlalchemy/sql/elements.py', line 263, in _execute_on_connection return connection._execute_clauseelement(self, multiparams, params) File '/Library/Python/2.7/site-packages/sqlalchemy/engine/base.py', line 1053, in _execute_clauseelement compiled_sql, distilled_params File '/Library/Python/2.7/site-packages/sqlalchemy/engine/base.py', line 1189, in _execute_context context) File '/Library/Python/2.7/site-packages/sqlalchemy/engine/base.py', line 1402, in _handle_dbapi_exception exc_info File '/Library/Python/2.7/site-packages/sqlalchemy/util/compat.py', line 203, in raise_from_cause reraise(type(exception), exception, tb=exc_tb, cause=cause) File '/Library/Python/2.7/site-packages/sqlalchemy/engine/base.py', line 1182, in _execute_context context) File '/Library/Python/2.7/site-packages/sqlalchemy/engine/default.py', line 470, in do_execute cursor.execute(statement, parameters) File '/Library/Python/2.7/site-packages/MySQLdb/cursors.py', line 205, in execute self.errorhandler(self, exc, value) File '/Library/Python/2.7/site-packages/MySQLdb/connections.py', line 36, in defaulterrorhandler raise errorclass, errorvalueProgrammingError: (_mysql_exceptions.ProgrammingError) (1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ’-10, 10’ at line 3') [SQL: u’SELECT post.id AS post_id, post.title AS post_title, post.text AS post_text, post.publish_date AS post_publish_date, post.user_id AS post_user_id nFROM post ORDER BY post.publish_date DESC n LIMIT %s, %s’] [parameters: (-10, 10)]127.0.0.1 - - [07/Jun/2017 14:44:06] 'GET /?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1' 200 -127.0.0.1 - - [07/Jun/2017 14:44:06] 'GET /?__debugger__=yes&cmd=resource&f=jquery.js HTTP/1.1' 200 -127.0.0.1 - - [07/Jun/2017 14:44:06] 'GET /?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1' 200 -(<type ’int’>, 1)127.0.0.1 - - [07/Jun/2017 14:44:06] 'GET / HTTP/1.1' 500 -Traceback (most recent call last): File '/Library/Python/2.7/site-packages/flask/app.py', line 1994, in __call__ return self.wsgi_app(environ, start_response) File '/Library/Python/2.7/site-packages/flask/app.py', line 1985, in wsgi_app response = self.handle_exception(e) File '/Library/Python/2.7/site-packages/flask/app.py', line 1540, in handle_exception reraise(exc_type, exc_value, tb) File '/Library/Python/2.7/site-packages/flask/app.py', line 1982, in wsgi_app response = self.full_dispatch_request() File '/Library/Python/2.7/site-packages/flask/app.py', line 1614, in full_dispatch_request rv = self.handle_user_exception(e) File '/Library/Python/2.7/site-packages/flask/app.py', line 1517, in handle_user_exception reraise(exc_type, exc_value, tb) File '/Library/Python/2.7/site-packages/flask/app.py', line 1612, in full_dispatch_request rv = self.dispatch_request() File '/Library/Python/2.7/site-packages/flask/app.py', line 1598, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File '/Users/andy/Desktop/Mastering Flask_Code Bundle/Chapter 3/chapter_3/main.py', line 114, in home top_tags=top_tags File '/Library/Python/2.7/site-packages/flask/templating.py', line 134, in render_template context, ctx.app) File '/Library/Python/2.7/site-packages/flask/templating.py', line 116, in _render rv = template.render(context) File '/Library/Python/2.7/site-packages/jinja2/environment.py', line 1008, in render return self.environment.handle_exception(exc_info, True) File '/Library/Python/2.7/site-packages/jinja2/environment.py', line 780, in handle_exception reraise(exc_type, exc_value, tb) File '/Users/andy/Desktop/Mastering Flask_Code Bundle/Chapter 3/chapter_3/templates/home.html', line 1, in top-level template code {% extends 'base.html' %} File '/Users/andy/Desktop/Mastering Flask_Code Bundle/Chapter 3/chapter_3/templates/base.html', line 45, in top-level template code {% block body %} File '/Users/andy/Desktop/Mastering Flask_Code Bundle/Chapter 3/chapter_3/templates/home.html', line 38, in block 'body' {{ render_pagination(posts, ’home’) }} File '/Library/Python/2.7/site-packages/jinja2/runtime.py', line 551, in _invoke rv = self._func(*arguments) File '/Users/andy/Desktop/Mastering Flask_Code Bundle/Chapter 3/chapter_3/templates/base.html', line 5, in template <a href='http://m.cgvv.com.cn/wenda/{{ url_for(’home’, page=pagination.prev().page) }}' aria-label='Previous'> File '/Library/Python/2.7/site-packages/flask_sqlalchemy/__init__.py', line 338, in prev return self.query.paginate(self.page - 1, self.per_page, error_out) File '/Library/Python/2.7/site-packages/flask_sqlalchemy/__init__.py', line 475, in paginate items = self.limit(per_page).offset((page - 1) * per_page).all() File '/Library/Python/2.7/site-packages/sqlalchemy/orm/query.py', line 2703, in all return list(self) File '/Library/Python/2.7/site-packages/sqlalchemy/orm/query.py', line 2855, in __iter__ return self._execute_and_instances(context) File '/Library/Python/2.7/site-packages/sqlalchemy/orm/query.py', line 2878, in _execute_and_instances result = conn.execute(querycontext.statement, self._params) File '/Library/Python/2.7/site-packages/sqlalchemy/engine/base.py', line 945, in execute return meth(self, multiparams, params) File '/Library/Python/2.7/site-packages/sqlalchemy/sql/elements.py', line 263, in _execute_on_connection return connection._execute_clauseelement(self, multiparams, params) File '/Library/Python/2.7/site-packages/sqlalchemy/engine/base.py', line 1053, in _execute_clauseelement compiled_sql, distilled_params File '/Library/Python/2.7/site-packages/sqlalchemy/engine/base.py', line 1189, in _execute_context context) File '/Library/Python/2.7/site-packages/sqlalchemy/engine/base.py', line 1402, in _handle_dbapi_exception exc_info File '/Library/Python/2.7/site-packages/sqlalchemy/util/compat.py', line 203, in raise_from_cause reraise(type(exception), exception, tb=exc_tb, cause=cause) File '/Library/Python/2.7/site-packages/sqlalchemy/engine/base.py', line 1182, in _execute_context context) File '/Library/Python/2.7/site-packages/sqlalchemy/engine/default.py', line 470, in do_execute cursor.execute(statement, parameters) File '/Library/Python/2.7/site-packages/MySQLdb/cursors.py', line 205, in execute self.errorhandler(self, exc, value) File '/Library/Python/2.7/site-packages/MySQLdb/connections.py', line 36, in defaulterrorhandler raise errorclass, errorvalueProgrammingError: (_mysql_exceptions.ProgrammingError) (1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ’-10, 10’ at line 3') [SQL: u’SELECT post.id AS post_id, post.title AS post_title, post.text AS post_text, post.publish_date AS post_publish_date, post.user_id AS post_user_id nFROM post ORDER BY post.publish_date DESC n LIMIT %s, %s’] [parameters: (-10, 10)]

問題解答

回答1:

看到你的sql語句

select * from 表 limit -10, 10

正確的應該是

select * from 表 limit 0, 10

你page傳入的是0吧?至少是1起始啊

回答2:

數據庫,表沒建好

標簽: Python 編程
主站蜘蛛池模板: 国产一级aa大片毛片 | 国产性tv国产精品 | 男女视频在线观看免费高清观看 | 全部免费的毛片视频观看 | 一级做人爱a视频正版免费 一级做性色a爱片久久片 | 成人国产精品高清在线观看 | 久操精品视频 | 亚洲精品视频免费在线观看 | 日韩在线第一区 | 在线视频一区二区三区在线播放 | 亚洲国产精品线观看不卡 | 欧美日韩一区二区三 | 亚洲综合色视频在线观看 | 久久精品久久精品国产大片 | 农村三级孕妇视频在线 | 国产一区二区三区免费在线观看 | 日韩精品一级毛片 | 国产精品三级a三级三级午夜 | 欧美一级成人影院免费的 | 欧美成人高清手机在线视频 | 精品在线小视频 | 高清一级毛片免免费看 | 中美日韩在线网免费毛片视频 | 中文字幕在线一区二区在线 | 人人公开免费超级碰碰碰视频 | 久久99久久成人免费播放 | 日韩成人中文字幕 | 国产精自产拍久久久久久蜜 | 一级毛片免费观看不卡视频 | 国产成人亚洲精品无广告 | 亚洲视频网站在线观看 | 久久精品道一区二区三区 | 欧美色道 | 在线国产高清 | 国产成 人 综合 亚洲绿色 | 精品欧美亚洲韩国日本久久 | 国产精品国产精品 | 国产精品99久久免费观看 | 免费一级欧美大片在线观看 | 国产一区二区日韩欧美在线 | 亚洲欧美中文字幕在线网站 |