Flask

Pagination in Flask using MySql

冷暖自知 提交于 2021-02-20 04:28:32
问题 I searched a lot about it. All the articles i get include SQLAlchemy and none of them deal with mysql. I am working with flask and i have a database in mysql and i need to display the data in pages. Like 1000 images, per page 10 so 100 pages. In mysql we can do pagination with the help of limit. And the routes can be: @app.route('/images', defaults={'page':1}) @app.route('/images/page/<int:page>') I need to ask is this all that is needed for pagination? or am i forgetting something important

Flask-Login, Session Management and AJAX

痞子三分冷 提交于 2021-02-20 00:13:10
问题 I'm having trouble getting an AJAX call to work with the Flask-Login current_user object and the @login_required decorator. I believe it has something to do with the session not being passed. The goal is for a user to click on a link that makes an AJAX call to a route URL that will provide a SSO session ID through a SOAP service. The SOAP service requires an emp_id to be passed which can be accessed through the current_user.emp_id attribute. I initially attempted the AJAX call without the

ImportError: cannot import name DispatcherMiddleware错误

守給你的承諾、 提交于 2021-02-19 17:01:26
执行脚本错误如下: root @ubuntu123 :/opt/miniNomad# python mini_jt.py Traceback (most recent call last): File "mini_jt.py", line 8, in <module> from flask_spyne import Spyne File "/usr/local/lib/python2.7/dist-packages/flask_spyne/__init__.py", line 1, in <module> from flask_spyne import Spyne, SpyneService, SpyneController File "/usr/local/lib/python2.7/dist-packages/flask_spyne/flask_spyne.py", line 3, in <module> from werkzeug.wsgi import DispatcherMiddleware ImportError: cannot import name DispatcherMiddleware 原因: 1、没有安装werkzeug 2、werkzeug的版本为1.0.0,这个版本中没有DispatcherMiddleware方法 解决办法: 卸载werkzeug

Python/Flask: Application is running after closing

折月煮酒 提交于 2021-02-19 08:06:11
问题 I'm working on a simple Flask web application. I use Eclipse/Pydev. When I'm working on the app, I have to restart this app very often because of code changes. And that's the problem. When I run the app, I can see the frame on my localhost, which is good. But when I want to close this app, just click on the red square which should stop applications in Eclipse, sometimes (often), the old version of application keeps running so I can't test the new version. In this case the only thing which

Python/Flask: Application is running after closing

♀尐吖头ヾ 提交于 2021-02-19 08:06:06
问题 I'm working on a simple Flask web application. I use Eclipse/Pydev. When I'm working on the app, I have to restart this app very often because of code changes. And that's the problem. When I run the app, I can see the frame on my localhost, which is good. But when I want to close this app, just click on the red square which should stop applications in Eclipse, sometimes (often), the old version of application keeps running so I can't test the new version. In this case the only thing which

Flask-WTF set time limit on CSRF token

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-19 03:49:46
问题 I'm currently using Flask-WTF v0.13.1, i have a few forms on my website, all created including the CSRF token. For some reasons i have to set a different expiration on each form, so far i could set manually the time_limit value upon creating the csrf token. I would like to update to the v0.14, according to the changelog time_limit is gone and there is no reference in the docs on how to change it anymore. Looking in the source code i saw that the form has a csrf_time_limit meta parameter. I

Why use flask open_resource

独自空忆成欢 提交于 2021-02-19 03:38:18
问题 while reading flask api documentation, I came across this open_resource method that opens file, like this with app.open_resource('schema.sql') as f: contents = f.read() do_something_with(contents) but why not just do this? with open('schema.sql') as f: contents = f.read() do_something_with(contents) I want to see a use case where app.open_resource could do something that open can't already do 回答1: From the docs: Opens a resource from the application’s resource folder. With app.open_resource ,

Can't transform geometry to geojson

China☆狼群 提交于 2021-02-19 02:30:20
问题 My problem is this. I'm creating a model for some data. class Cables(Base): __tablename__ = 'cables' id = Column(Integer, nullable=False) route = Column(Geometry(geometry_type='LINESTRING', srid=4326), nullable=False) Now, I want to transform such a route to GeoJSON. Things I've tried @app.route("/api/cable/<int:id>", methods=['GET']) def get_cable(id): cable = session.query(Cables).filter(Cables.id == id).first() return str(geoalchemy2.functions.ST_AsGeoJSON(cable.route)) returns ST

Render HTML tags from variable without escaping [duplicate]

邮差的信 提交于 2021-02-19 02:12:57
问题 This question already has answers here : Passing HTML to template using Flask/Jinja2 (6 answers) Closed 5 years ago . I have some HTML content that I want to pass to the template to render. However, it escapes the tags to use HTML entities ( < ), so they show up as code rather than markup. How can I render the html passed to the template? tags = """<p>some text here</p>""" render_template ('index.html',tags=tags) {{ tags }} '< some text here >' I want a paragraph with the text though. some

Render HTML tags from variable without escaping [duplicate]

主宰稳场 提交于 2021-02-19 02:11:26
问题 This question already has answers here : Passing HTML to template using Flask/Jinja2 (6 answers) Closed 5 years ago . I have some HTML content that I want to pass to the template to render. However, it escapes the tags to use HTML entities ( < ), so they show up as code rather than markup. How can I render the html passed to the template? tags = """<p>some text here</p>""" render_template ('index.html',tags=tags) {{ tags }} '< some text here >' I want a paragraph with the text though. some