草庐IT

Flask_FileUpload

全部标签

python - 使用 flask 从选择标签中获取值(value)

我是Flask的新手,我无法从我的选择标签中获取值。我尝试过返回错误请求的request.form['comp_select']。但是,当我尝试使用request.form.get('comp_select')时,我的返回页面会返回一个空白列表“[]”。我的html:Pleaseselect{%foroindata%}{{o.name}}{%endfor%}Go我的app.py:@app.route("/test",methods=['GET','POST'])deftest():select=request.form.get('comp_select')return(str(sele

python - 使用 flask-restful RequestParser 进行嵌套验证

使用flask-restful微框架,我在构建将验证嵌套资源的RequestParser时遇到问题。假设表单的预期JSON资源格式:{'a_list':[{'obj1':1,'obj2':2,'obj3':3},{'obj1':1,'obj2':2,'obj3':3}]}a_list中的每一项都对应一个对象:classMyObject(object):def__init__(self,obj1,obj2,obj3)self.obj1=obj1self.obj2=obj2self.obj3=obj3...然后使用类似以下的表单创建一个RequestParser:fromflask.ext

python - ImportError : No module named flask. ext.login

flask_login模块有问题。我已经成功安装了flask_login模块。同样从命令提示符我可以很容易地运行这个脚本,没有错误:Python2.7(r27:82525,Jul42010,07:43:08)[MSCv.150064bit(AMD64)]onwin32Type"help","copyright","credits"or"license"formoreinformation.>>>fromflask.ext.loginimportLoginManager但是当我运行这个脚本时:fromflaskimportFlaskfromflask.ext.loginimportLog

python - Flask - 如何创建自定义 abort() 代码?

Flask通过使用abort()或在错误真正发生时具有良好的错误处理程序。Flask文档中有一个错误404处理程序的示例:@app.errorhandler(404)defnot_found(error):returnrender_template('404.html'),404所以,我尝试创建自定义错误代码,如ifFalse:abort(777)@app.errorhandler(777)defsomething_is_wrong(error):returnrender_template('777.html'),777但它不起作用,Werkzeug调试器说:LookupError:n

python - Flask,使用 send_static_file 不断获取 404 服务静态文件

我按照HowtoservestaticfilesinFlask的指示进行操作,但仍然无法正常工作。这是我的项目结构:Project_path|+--app|||+--main.py+--static|+--js|+--jquery-1.11.2.min.js这里是main.py:@app.route('/js/')defserve_static(path):root_dir=os.path.dirname(os.getcwd())print(os.path.join(root_dir,'static','js',path))returnapp.send_static_file(os.p

python - SqlAlchemy 和 Flask,如何查询多对多关系

我需要帮助创建SqlAlchemy查询。我正在做一个使用SqlAlchemy的Flask项目。我在我的models.py文件中创建了3个表:Restaurant、Dish和restaurant_dish。restaurant_dish=db.Table('restaurant_dish',db.Column('dish_id',db.Integer,db.ForeignKey('dish.id')),db.Column('restaurant_id',db.Integer,db.ForeignKey('restaurant.id')))classRestaurant(db.Model)

python - 是否可以在 Flask 中发出 POST 请求?

Flask需要从服务器端发出POST请求。假设我们有:@app.route("/test",methods=["POST"])deftest():test=request.form["test"]return"TEST:%s"%test@app.route("/index")defindex():#Istheresomething_like_thismethodinFlasktoperformthePOSTrequest?returnsomething_like_this("/test",{"test":"MyTestData"})我没有在Flask文档中找到任何具体内容。有人说url

python - Web 应用程序中的动态子域处理(Flask)

关闭。这个问题需要更多focused.它目前不接受答案。想要改进这个问题吗?更新问题,使其只关注一个问题editingthispost.关闭8年前。Improvethisquestion我将使用flask创建一个Web应用程序,应用程序的一部分将涉及一个子域(例如,user1.appname.org)。我不确定如何在flask配置中动态创建这些子域,或者如何将它们部署到生产服务器。最好的方法是什么? 最佳答案 所有Flask的路由结构都支持subdomain关键字参数(这包括对路由变量的支持)。@app.route("/",subd

python - 如何在 Flask-Login 中实现 user_loader 回调

我正在尝试使用Flask和Flask-Login在Flask应用程序中实现用户身份验证的扩展。目标是从数据库中提取用户帐户信息,然后登录用户,但我卡住了;但是,我已将其范围缩小到Flask-Login行为的特定部分。根据Flask-Logindocumentation,我需要创建一个user_loader“回调”函数。这个函数的实际目的和实现让我困惑了几天:Youwillneedtoprovideauser_loadercallback.ThiscallbackisusedtoreloadtheuserobjectfromtheuserIDstoredinthesession.Itsh

python - Flask中返回响应后需要执行一个函数

仅对于一个请求,我需要在向客户端发送响应后执行一项功能。因为该函数需要时间并且最终导致连接超时Socketerror:[Errno32]BrokenpipeFlask中有没有办法在返回请求后执行函数 最佳答案 我将公开我的解决方案。在flask路由调用的函数中返回某些内容后,您可以使用线程来计算任何内容。importtimefromthreadingimportThreadfromflaskimportrequest,Flaskapp=Flask(__name__)classCompute(Thread):def__init__(s