我已经构建了一个包含简单Flask测试应用程序的Docker镜像:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello_world():
return "Hello World!"
if __name__ == "__main__":
app.run(debug=True,host='0.0.0.0')
Run Code Online (Sandbox Code Playgroud)
使用Dockerfile:
FROM ubuntu:latest
RUN apt-get update -y
RUN apt-get install -y python-pip python-dev build-essential
COPY . /app
WORKDIR /app
RUN pip install -r /app/requirements.txt
ENTRYPOINT ["python"]
CMD ["app.py"]
Run Code Online (Sandbox Code Playgroud)
Docker镜像是使用构建的docker build -t flask-app .,并且已成功创建:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
flask-app latest fab0d79fd7ac 8 minutes ago 642.2 MB
ubuntu latest 104bec311bcd 5 weeks ago 129 …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一种方法来生成高斯整数的高斯除数序列 - 高斯整数是正整数或复数g = a + bi,其中a和b都是整数,高斯整数的高斯除数g是高斯整数d这g / d也是高斯整数.
我有以下代码.
def is_gaussian_integer(c):
"""
Checks whether a given real or complex number is a Gaussian integer,
i.e. a complex number g = a + bi such that a and b are integers.
"""
if type(c) == int:
return True
return c.real.is_integer() and c.imag.is_integer()
def gaussian_divisors(g):
"""
Generates a sequence of Gaussian divisors of a rational or Gaussian
integer g, …Run Code Online (Sandbox Code Playgroud) 我有一个简单的 Flask 应用程序(Flask 版本1.0.3),只有一个应用程序。/ask用于处理(名称、值)对的 POST 查询字符串的URL 和处理程序,但该request.args对象不存储所有参数对,仅存储第一对。为什么其他人都退学了?
我已经尝试打印出该request.args对象,但它只显示第一个参数对。
这是 Flask 应用程序
import json
from flask import (
Flask,
jsonify,
request,
Response
)
app = Flask(__name__)
@app.route('/')
def home():
return jsonify(message="Hello, World!")
@app.route('/ask', methods=['POST'])
def ask():
return str(request.args)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)
Run Code Online (Sandbox Code Playgroud)
这是使用 CLI 工具的简单查询http,带有两个参数和响应参数 - 请注意响应参数仅包含第一个参数
$ http POST http://127.0.0.1:5000/ask?q1=name&q2=address
[1] 58720
[2019-06-12 15:29:27 $ HTTP/1.0 200 OK
Content-Length: 36
Content-Type: text/html; charset=utf-8
Date: Wed, 12 Jun …Run Code Online (Sandbox Code Playgroud)