草庐IT

flask-RESTless

全部标签

python - 常量 Flask session ID

我有一个Flask应用程序,使用Nginx+WSGI(FastCGI和Gevent)并使用标准Flasksession。我不使用session.permanent=True或任何其他额外选项,而只是在默认配置中设置SECRET_KEY。我不在session中保存任何(键,值)对,并且只依赖于SID=session['_id']条目来识别返回用户。我使用以下代码读取SID:@page.route('/')defmain(page='home',template='index.html'):ifnotrequest.args.get('silent',False):print>>sys.s

python - 为什么 coverage.py 不能正确测量 Flask 的 runserver 命令?

我正在尝试找出Flask应用程序的哪些行正在运行。我这样启动Flask:coveragerunmanage.pyrunserver输出看起来像这样:*Runningonhttp://127.0.0.1:5000/*Restartingwithreloadermanage.py看起来像这样:#!/usr/bin/envpythonfromflask.ext.scriptimportManagerfrommy_flask_appimportappmanager=Manager(app)if__name__=='__main__':manager.run()然后我通过HTTP访问应用程序的各

jquery - 使用 Flask 执行 AJAX POST,然后执行 GET

我的目标是让用户填写一个表单,在POST请求中将该信息发送到Flask服务器,然后使用该表单信息呈现一个模板(在服务器上经过一些逻辑处理之后)。到目前为止,我已经完成了所有这些的POST部分。我现在正在尝试在ifrequest.method==POST'中呈现一个模板,我想这现在不起作用。这是我目前的代码:@app.route('/filteredsearch/',methods=["GET","POST"])deffilteredsearch():ifrequest.method=='POST':data=json.loads(request.data)tables=data['ch

python - 使用 Flask、WTForm、SQLAlchemy 和 Jinja2 的完整多对一示例

这是我的HTML下拉菜单。该值为子表的主键。CategoryNumberOneCategoryNumberTwo我需要将Post.category_id的值更新为整数1而不是“类别编号一”。这是我的代码。#createnewpost@app.route('/admin/post',methods=['GET','POST'])@login_required#RequiredforFlask-Securitydefcreate_post():form=PostForm()ifform.validate_on_submit():post=Post(title=form.title.data

python - flask 测试客户端 : Testing DELETE request with data

我正在尝试使用来自http://flask.pocoo.org/docs/testing/的建议来测试我的Flask应用程序,但我无法弄清楚如何使用表单数据测试DELETE方法。我的删除方法看起来像这样:fromflask.ext.restfulimportResource,reqparse...defdelete(self):self.reqparse.add_argument('arg1',type=str,required=True,location='form')args=self.reqparse.parse_args()...我想测试一下:defsetUp(self):se

python - 如何在 Flask 上捕获这样的异常?

我像这样运行一个简单的flask应用程序:fromflaskimportFlaskapp=Flask(__name__)@app.route('/')defwelcome():return"OK"app.config.update(DEBUG=True)if__name__=='__main__':app.run(use_reloader=False)当我运行并访问它时,有时(并非总是)它无法响应请求并抛出异常:Exceptionhappenedduringprocessingofrequestfrom('127.0.0.1',54481)Traceback(mostrecentcal

python - 单独模块中的 Flask View

flask#flaskr.pyfromflaskimportFlaskapp=Flask(__name__)importviewsif__name__=="__main__":app.run()View.py#views.pyfromflaskrimportappfromflaskimportrender_template,g@app.route('/')defshow_entries():entries=Nonereturnrender_template('show_entries.html',entries=entries)python3flaskr.py谁能告诉我为什么这不起作用

python - 如何使用 Flask 测试客户端发布多个文件?

为了测试Flask应用程序,我得到了一个带有文件作为附件的Flask测试客户端POSTing请求defmake_tst_client_service_call1(service_path,method,**kwargs):_content_type=kwargs.get('content-type','multipart/form-data')withapp.test_client()asclient:returnclient.open(service_path,method=method,content_type=_content_type,buffered=True,follow_

python - Flask: fork 环境

在Flask-QuickStart浏览Flask文档时我看到了以下段落。AttentionEventhoughtheinteractivedebuggerdoesnotworkinforkingenvironments(whichmakesitnearlyimpossibletouseonproductionservers),itstillallowstheexecutionofarbitrarycode.Thismakesitamajorsecurityriskandthereforeitmustneverbeusedonproductionmachines.我搜索了stackove

python - Flask - WSGI - 没有名为 'flask' 的模块

我一直在关注Sentdex的Flask教程。他正在使用Venv来设置他的Flask,但没有将他的Python设置为与Venv一起工作。我已经尝试在全局范围内安装Flask-但它仍然无法正常工作。尝试浏览到服务器返回500内部服务器错误我遇到了常见的nomodulenamedflask错误。errorFGL.log[SunFeb0511:22:32.0439252017][wsgi:error][pid26340:tid118578538694400][client86.52.205.25:49814]mod_wsgi(pid=26340):TargetWSGIscript'/var/w