Flask

Flask: Is it possible to Mask a URL with variables?

[亡魂溺海] 提交于 2020-08-06 05:45:38
问题 I want to pass variables from a site to another. This is no problem, as there are many ways to do it. I'm struggling though, in how I can 'hide' these variables in the URL, and yet be able to get the values. Ex.: If I use 'request.args.get': @page.route('/users', methods=['GET', 'POST']) def users(): user = request.args.get('user') return render_template('users.html', user=user) When I click in the link, the URL generated is: http://localhost:5000/users?user=john My goal is to access the

FlaskCon:社区举办的第一届线上 Flask 大会

好久不见. 提交于 2020-08-06 04:22:20
FlaskCon 是一个社区举办的 Flask 大会。按照官方的介绍,它: 100% Remote 100% Free 100% Community-driven 和 DjangoCon 类似,FlaskCon 会专注于 Flask 相关话题,包括 Flask 扩展介绍、开发经验、最佳实践、类似框架的对比等等。大会将会在 6 月 26 号举行,如果担心错过,可以在日历里设个提醒,临近的时候我也会再发一篇提醒文章。 如果你想分享 Flask 开发相关的经验,介绍你对 Flask 的有趣应用,或者是有任何和 Flask 相关而且你很想拿出来聊一聊的话题,欢迎 报名演讲 。演讲有 20 分钟和 40 分钟两种类型,需要使用英语。 你可能会觉得大会的 Logo 不是很好看……不要担心,这些设计还在慢慢改进中,如果你有任何和大会网站、议程设置、设计相关的建议,可以发邮件到 flaskcon@gmail.com ,或是在 Discord 频道 和 Reddit 主题帖 里反馈。 P.S. 如果你想帮忙改进大会网站,最直接的方式是自己动手修改 源码 。 相关链接: 大会官网: https:// flaskcon.com/ 提交议题申请: https:// sessionize.com/flaskcon 原文链接: http:// greyli.com/flaskcon-202 0/ 来源:

flask-migrate的使用

自作多情 提交于 2020-08-05 09:26:37
manager.py代码如下: from flask_script import Manager, Shell, Server from flask_migrate import Migrate, MigrateCommand from app.ext import db from app import create_app app = create_app() manager = Manager(app=app) migrate = Migrate(app, db) def make_shell_context(): return dict(app=app) manager.add_command("shell", Shell(make_context=make_shell_context)) manager.add_command("run_dev", Server(use_debugger=True, use_reloader=True)) manager.add_command("runserver", Server()) manager.add_command("db", MigrateCommand) @manager.command def deploy(): """run deployment tasks""" pass if __name__ == "__main

【2020Python修炼记】web框架之 Django框架基础

女生的网名这么多〃 提交于 2020-08-05 03:05:04
【目录】 一、引子 二、 Django框架 一、引子 1、后端举足轻重的地位 前端 —————— 后端 ———————— 数据库 2、接下来,一起靠近Django框架 纯手撸web框架 # HTTP协议 """ 网络协议 HTTP协议 数据传输是明文 HTTPS协议 数据传输是密文 websocket协议 数据传输是密文 四大特性 1.基于请求响应 2.基于TCP、IP作用于应用层之上的协议 3.无状态 4.短/无链接 数据格式 请求首行 请求头 请求体 响应状态码 1XX 2XX 200 3XX 4XX 403 404 5XX 500 """ # 如何做到后缀的不同返回不同的内容 # 拿到用户输入的后缀 做判断 # 不足之处 1 .代码重复(服务端代码所有人都要重复写) 2 .手动处理http格式的数据 并且只能拿到url后缀 其他数据获取繁琐(数据格式一样处理的代码其实也大致一样 重复写) 3.并发的问题 借助于wsgiref模块 """ urls.py 路由与视图函数对应关系 views.py 视图函数(后端业务逻辑) templates文件夹 专门用来存储html文件 """ # 按照功能的不同拆分之后 后续添加功能只需要在urls.py书写对应关系然后取views.py书写业务逻辑即可 动静态网页 """ 静态网页 页面上的数据是直接写死的 万年不变 动态网页

flask 部署算法模型

℡╲_俬逩灬. 提交于 2020-08-05 01:59:50
了解一点web知识,看一下flask教程就能使用flask写简单的demo. 在flask中加个载入模型函数,随服务启动将模型载入内存,将预测函数放进接收数据函数中,拿到数据即进行预测 #encoding:utf-8 from keras.applications import ResNet50 from PIL import Image import numpy as np import flask import io import tensorflow as tf app = flask.Flask(__name__) model = None #载入模型 def load_model(): global model model = ResNet50(weights="imagenet") global graph graph = tf.get_default_graph() #不加这个会报错 #预处理数据 def prepare_image(image): return image #路由 预测 @app.route("/predict", methods=["POST"]) def predict(): #获取http传来数据 if flask.request.method == "POST": if flask.request.files.get("image"):

自学 Python,视频教程和代码一看就懂,动手就废,应该这么学

强颜欢笑 提交于 2020-08-04 16:24:48
​ 一、代码量太少了,看得多做得少,导致一做就错。 每一个测试工程师必定是在大量的时间和代码中提升的自己,如果你只是看视频的话,那永远都停留在理论上,很多问题是要实践才能发现的 我打个比方你看视频的时候可能觉得写一个函数程序太简单了,几乎一秒钟就看懂了,因为没什么逻辑,非常简单,但是当你实践的时候你有可能会出现以下的一些问题 1、运行没有出现任何结果(因为没有调用) 2、运行后报语法错误(函数后面要带英文的冒号:) 3、Python环境配置错误 4、也有可能传参错误 ​ 二、没搞懂的问题没有得到及时的解答 在咱们自学的道路上遇到问题肯定是非常正常的,也是任何一个开发人员都经常要面对的,遇到了问题没有得到解答那肯定就会影响到后面的学习。 我打个比方,你Python基础没有好学,你就去学selenim或者appium,或者接口自动,前期搁置的问题如果越来越多累计多了就导致自己感觉学得差不多了,但是做一个最基本的接口项目都做不出来,更不用说学后面的框架了。大家在学的时候尽可能的把问题解决了再继续学习后面的, 学习最重要的是学懂而不是学完 ,我这边整理了很多关于新手遇到的问题。当然我也建议大家下载一个有道云笔记,把学习中的笔记或者是遇到的问题对应的解决方法都记上去,这样走在哪里都可以直接打开了看,也可以记录在博客上,这样对于你们以后面试的时候也有优势

是不是有一天想象着让代码自动补全,今天他来了!!!

爷,独闯天下 提交于 2020-08-04 11:57:39
作者:熊唯,黄飞 ,腾讯 PCG/QQ研发中心/CV应用研究组 AI 如果真的可以写代码了,程序员将何去何从?近几年,NLP 领域的生成式任务有明显的提升,那通过 AI 我们可以让代码自动完成后续补全吗?本文主要介绍了如何使用 GPT2 框架实现代码自动补全的功能。 如果 AI 真的可以自己写代码了,程序员将何去何从? 我去年做过一个代码补全的小功能,打包为 androidStudio 插件,使用效果如下: 代码补全模型预测出的结果有时的确会惊吓到我,这也能学到~? 那如果给它见识了全世界的优秀代码,再给足够量级参数和优秀的模型框架,真的可以实现需求作为输入,直接输出代码吗? "我的需求讲完了,你的代码呢?" 希望可以看到这一天。 代码补齐功能有其他优秀插件也已实现,比如 tabnine,Kite 和国产的 aixcoder。本文主要介绍下代码补全功能需要实现的整套流程。主要包括数据,算法和工程。 数据 众所周知,算法工程师大部分时间都在处理数据。 深度学习是使用大数据训练模型的一个过程,数据是很重要的一个模块。人是会累的,休息不好还导致记忆不好。AI 是你给多少数据它就能存储接收多少数据,学不到信息那是人的错,给的数据不好或者算法设计不好。所以我们先尽可能多的准备好训练数据。 1、数据采集 本文的目的是代码补全,训练数据就是代码段。考虑到每种语言风格和语法都不一致

Set default value for select html element in Jinja template?

拥有回忆 提交于 2020-08-02 06:09:52
问题 I'm using flask/jinja in order to make a simple web application. I have a table of records which is taken from a db table, and is called by a webpage which loads the list of records. On each row there is a dropdown list (done using the select HTML tag) on a column. I realize the below code doesn't do what its supposed to, currently the last option (fourth) is automatically selected because of the selected tag. I've left it in to try show what I'm trying to implement. Ideally I'd want it to

Set default value for select html element in Jinja template?

二次信任 提交于 2020-08-02 06:08:53
问题 I'm using flask/jinja in order to make a simple web application. I have a table of records which is taken from a db table, and is called by a webpage which loads the list of records. On each row there is a dropdown list (done using the select HTML tag) on a column. I realize the below code doesn't do what its supposed to, currently the last option (fourth) is automatically selected because of the selected tag. I've left it in to try show what I'm trying to implement. Ideally I'd want it to

Flask-Pandas Creating a download file [duplicate]

纵然是瞬间 提交于 2020-08-02 04:25:17
问题 This question already has answers here : Writing then reading in-memory bytes (BytesIO) gives a blank result (2 answers) Closed 3 years ago . I have a small app where I input a few csv files, do some data processing with pandas and eventually I would like to have the results spit out an excel file once it is done. Right now I can render the results of the processing to html and I have a table up and running. However the issues comes when I try to create an excel file for download. Below is