Flask

Flask is a web microframework, it is a Python module that allows you to easily develop web applications without providing rules and specific methods to follow

Flask application structure

  • server.py: This is one of our files that contains all the logic of Flask to run the main entry point of the application

  • templates directory: By default, Flask will look for any folder of markup files in the template, but you can configure HTML files in different folders

  • static directory: In our Flask application, we use static folders to keep our static files, including images, JavaScript and CSS codes

When creating a python application, it is recommended to keep the virtual environment so that you will not interfere with the global local environment, and since we will create a minimalistic Flask application, we will not use static files, so we don’t need static folders

server.py

from flask import Flask, render_template, request

app = Flask(__name__)

@app.route('/register', methods = ["GET", "POST"])
def register():
   if request.method == "POST":
       username = request.form["username"]
       email = request.form["email"]
       password = request.form["password"]
   return render_template('register.html')

if __name__ =='__main__':
    app.run(debug=True)

Templates/register.html

<html>
  <head>
    <title>Welcome to our registration page</title>
  </head>
  <body>
  <form>
    Username <input type = "text" name= "username" />
    Email <input type = "text" name = "email" />
    Password <input type = "text" name = "password" />
  </form>
  </body>
</html>

Dockerfile

FROM python:3.6-alpine

COPY .app

COPY ./requirements.txt /app/requirements.txt

WORKDIR app

EXPOSE 5000:5000

RUN pip install -r requirements.txt

CMD ["python", "server.py"]

Build a mirror

docker build -t flaskimage.

Run the container

docker run -t -i flaskimage
点赞(0)

评论列表 共有 0 评论

暂无评论

微信服务号

微信客服

淘宝店铺

support@elephdev.com

发表
评论
Go
顶部