Flask

Running Flask on bash: Could not import “app”

旧城冷巷雨未停 提交于 2021-01-05 07:24:39
问题 I made this code on Flask: from flask import Flask app = Flask(__name__) @app.route('/') def index(): return "hi" Even so, fi I try to run it with flask run it shows this message: * Serving Flask app "app.py" * Environment: production WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Debug mode: off Usage: flask run [OPTIONS] Error: Could not import "app". What am I doing wrong? Edit: App structure: website/ | - app.py 回答1

Flaskr url_for with parameters not working when called from javascript to python

人盡茶涼 提交于 2021-01-04 15:57:35
问题 I am in the middle of creation of a web application. In javascript, I make a ajax call to my python script, process and send the result back as response. /process/ is the route to the python script for the processing of values which are sent as json, namely value1 and value2. I send back response as json setting value in key 'result'. In the success block of ajax, the value is stored in name_value and this should be passed as parameter to the python routing method. Javascript: $.ajax({ type:

Flaskr url_for with parameters not working when called from javascript to python

时光总嘲笑我的痴心妄想 提交于 2021-01-04 15:55:11
问题 I am in the middle of creation of a web application. In javascript, I make a ajax call to my python script, process and send the result back as response. /process/ is the route to the python script for the processing of values which are sent as json, namely value1 and value2. I send back response as json setting value in key 'result'. In the success block of ajax, the value is stored in name_value and this should be passed as parameter to the python routing method. Javascript: $.ajax({ type:

Flask Restful NoAuthorizationError Missing Authorization Header

∥☆過路亽.° 提交于 2021-01-04 04:30:04
问题 I'm running Flask Restful on a server in production mode using Python 3.6 and hitting an endpoint that requires jwt auth, but I keep getting a "NoAuthorizationError Missing Authorization Header" error. The strange part is that the very same request is sent using Postman to the local version of the exact same Flask app on my mac and it works just fine without any errors. The problem only occurs on the live server and all of the pip packages are the exact same version as well. UPDATE I am using

Flask Restful NoAuthorizationError Missing Authorization Header

我的未来我决定 提交于 2021-01-04 04:27:29
问题 I'm running Flask Restful on a server in production mode using Python 3.6 and hitting an endpoint that requires jwt auth, but I keep getting a "NoAuthorizationError Missing Authorization Header" error. The strange part is that the very same request is sent using Postman to the local version of the exact same Flask app on my mac and it works just fine without any errors. The problem only occurs on the live server and all of the pip packages are the exact same version as well. UPDATE I am using

摸鱼 | 有内鬼,停止交易 ( 推荐两个 Github 项目)

安稳与你 提交于 2021-01-03 08:47:53
这个周末没有学习,连摸鱼都争分夺秒。 光光加班就夺走了我周末一天半的时间,感谢领导至少让我在家睡觉而不是在公司通宵。 感恩。 技术文这周写了一些,今天不聊技术,分享两个 Github 项目。 有内鬼,停止交易 一个生成诺基亚的信息截图,可以玩一玩,蛮有意思的。 https://github.com/dcalsky/zzkia 代码可以使用 Docker 直接部署,作者连 Dockerfile 与 docker-compose 配置文件都一并上传了,可以说很贴心。 可以先看看咸鱼生成的样例: 大家可以自己部署一个也可以使用作者搭建好的案例。 https://zzkia.noddl.me:8020/ 这个网站访问较卡,动手能力强的朋友可以参考咸鱼之前写过的 docker 教程自己搭建。 http://mp.weixin.qq.com/mp/homepage?__biz=MzIwNDI1NjUxMg==&hid=3&sn=fd02a149bab8c72908341b6523af7c42&scene=126&sessionid=1571571392&subscene=0&clicktime=1571571396#wechat_redirect flask-restful-example https://github.com/qzq1111/flask-restful-example

werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand. KeyError: 'id'

假装没事ソ 提交于 2021-01-03 06:40:12
问题 html page {%block title%}Login page{% endblock %} {%block content%} <form action = '#' method="post"> <p>creds:</p> <p><input type="number" placeholder="id" Id="id" /></p> <p><input type="text" placeholder="nm" name="nm" /></p> <p><input type="submit" value="submit" /></p> </form> {%endblock%} app code @app.route("/") def home(): return render_template("login.html") @app.route("/",methods = ["POST","GET"]) def post(): if request.method == "POST": user = request.form['nm'] id = request.form[

用Python进行Web开发,零基础学习Python编程路线

▼魔方 西西 提交于 2021-01-02 13:14:29
Web开发这样一个大概念,对小白来说,想学也不知道从哪下手,当今Web开发的一大热门语言是Python,从Python入手,学习Web后端开发,也许要容易些。 1 WSGI, 即Web Server Gateway Interface Web开发有两大基础: HTTP协议 HTML语言 HTTP协议在Web领域的重要性不必赘述,这样一个重要的概念,如果交给开发者去实现,且不谈编程,单是看懂庞大的协议,就会花掉大量的时间。好在我们意识到,实现协议的工作,显然是可重复利用的。可重复利用的HTTP协议实现,被封装在Python库里,就有了Python进行Web开发最基本的一个库:WSGI(Web Server Gateway Interface)。WSGI为开发者封装了HTTP协议的实现,将网络通信抽象为接收数据报和发送数据报的简单函数。对HTTP协议有基本了解的读者可以看一看下面的例子。 def application (environ, start_response): start_response('200 OK', [('Content-Type', 'text/html')]) return '<h1>Hello World!</h1>' 上面的这个函数就是WSGI规定的函数形式,接收两个参数environ, start_response,返回header和body

Python除了做ai,还能干啥?

巧了我就是萌 提交于 2021-01-02 08:47:59
先说个笑话,很多人一开始学习 Python 的时候,会感到无聊和枯燥,因为一开始都不知道那些循环语句呀、列表呀、元组等知识点的用武之地,所以慢慢的就没什么动力了,然后就去买滑板鞋,开始在地上摩擦,像魔鬼的步伐。逢人就说:“Python没用,这玩意不好找工作,就是拿来玩玩~” 最近有不少 b 友想知道 Python 除了爬虫之外,还能玩点啥呢?那么小帅b接下来就来说说我知道的可以使用 Python 做的事情,让你发现更多的方向。 1、爬虫 这玩意不用我多说了,我最近分享的大部分教程就是爬虫,如果你对爬虫感兴趣的话可以看看我之前写的那些文章,也可以看看这个: python如何赚钱?python爬虫如何进阶?python就业?如何快速入门python?..... 2、数据分析 现在的人们越来越不理智了,总是把自己的想法强加到别人的身上,“感觉”会欺骗人,但是“数据”不会,数据是相对来说比较真实的反应,打开你的手机,看看在哪个应用的用时最长,你说你每天学习,但是一看,挖槽,抖音用了 3 个小时,PornHub 看了 4 个小时,你说你在学习? 这就是数据分析最简单的解释,对我们比较重视的事情,通过数据进行可视化分析,Python 让你理智些,克制些。 3、机器学习 现在不是各种吹人工智能么,机器学习就是人工智能的一个分支,它的应用太广泛了,比如自然语言处理,搜索引擎,各种识别技术