草庐IT

Flask-Migrate

全部标签

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

python - Flask/Werkzeug 调试器、进程模型和初始化代码

我正在使用Flask编写一个Python网络应用程序。我的应用程序在启动时与另一台服务器建立连接,并在后台定期与该服务器通信。如果我不使用Flask的内置调试器(使用debug=False调用app.run),没问题。如果我确实使用内置调试器(使用debug=True调用app.run),Flask会使用相同的代码启动第二个Python进程。最终监听HTTP连接的是子进程,并且通常表现得像我的应用程序应该的那样,我假设当调试器启动时,父进程就在那里监视它。然而,这对我的启动代码造成了严重破坏,它在两个进程中运行;我最终有2个到外部服务器的连接,2个进程记录到同一个日志文件,并且通常,它

python - Flask 和 WTForms - 如何让 wtforms 刷新选择的数据

我使用的是最新版本的flask、wtforms和Flask-WTForms。我有一个显示表单的页面,其中一个是带有选项“A”的选择框。应用程序启动时一切正常。在另一种形式中,我添加了一条名为“B”的记录。现在,我想要的表单应该有带有选项A和B的选择框,只有选项A可用。我必须杀死uWSGI并重新启动才能让wtforms刷新数据。那么,我错过了什么?如何让wtforms刷新数据?以下是我如何创建表单,其中getAgencyList返回要添加到选择框的选项列表。在另一个对话中,我添加了一个代理机构,并且无需重新启动应用程序即可更新代理机构列表:classcreateUser(Form):""

python - 使用 jQuery Mobile 在 Flask 中调用重定向(url_for ('xxx'))后浏览器中的 URL 未更新

我有一个使用Flask的非常简单的python程序,如下所示。它处理带有弹出窗口和注销的登录。问题是浏览器中的url没有被redirect(url_for())调用更新。@app.route('/')defindex():ifnot'username'insession:#containsabuttonshowingaloginpopupformwithactionsetto'/login'returnrender_template('welcome.html')else:#containsalogoutbuttonwithahrefto'/logout'returnrender_te

python - 你如何在 Flask 中调试 url 路由?

我正在使用VisualStudio2013的PythonTools开发一个Flask网站,它有自己的调试器,它允许我单步执行初始设置代码,直到app.run()然而我要调试的代码是路由代码,像这样:@app.route('/')defurl_index():returnrender_template('index.html')我知道该函数正在运行,因为服务器确实以index.html响应,但如果我在最后一行放置断点,它永远不会被击中。有什么方法可以调试这些路由功能吗?Flask说它带有调试器,但我该如何使用它呢?它与VisualStudio兼容吗? 最佳答案

python - 如何从 Python 中的 Flask 应用程序调用某些函数?

我的myapp.py是这样的:fromflaskimportFlaskfromflaskimportrequestfromflaskimportrender_templateapp=Flask(__name__)@app.route('/',methods=['GET','POST'])defindex():ifrequest.method=='POST':#dosomething#forexample:message='IamfromthePOSTmethod'f=open('somefile.out','w')print(message,f)returnrender_templat