FLASK框架應用例項

2021-09-08 12:47:15 字數 4848 閱讀 6072

主目錄資料夾如下:

total 60

drwxr-xr-x 3 root root 4096 jan 10 16:38 config

drwxr-xr-x 3 root root 4096 jan 10 16:38 controller

drwxr-xr-x 5 root root 4096 jan 10 16:38 file

drwxr-xr-x 2 root root 4096 jan 10 16:38 html

drwxr-xr-x 3 root root 4096 jan 10 16:38 lib

drwxr-xr-x 2 root root 4096 jan 10 16:38 logs

drwxr-xr-x 3 root root 4096 jan 10 16:38 middleware

drwxr-xr-x 3 root root 4096 jan 10 16:38 module

-rw-r--r-- 1 root root 210 dec 29 20:35 nohup.out

drwxr-xr-x 2 root root 4096 jan 10 16:38 python

drwxr-xr-x 5 root root 4096 jan 10 16:38 raindb

drwxr-xr-x 2 root root 4096 jan 10 16:38 register

目錄樹如下:

.├── config

│ ├── __pycache__

│ │ └── rainconfig.cpython-36.pyc

│ └── rainconfig.py

├── controller

│ ├── __pycache__

│ │ └── raincontroller.cpython-36.pyc

│ └── raincontroller.py

├── file

│ ├── css

│ │ └── entrance.css

│ ├── img

│ │ └── entrance.png

│ └── js

│ ├── entrance.js

│ └── min.js

├── html

│ ├── entergoin.html

│ ├── entrance.html

│ └── error.html

├── lib

│ └── raindborm

│ ├── __init__.py

│ ├── __main.py

│ └── __pycache__

│ ├── __init__.cpython-36.pyc

│ ├── __main.cpython-36.pyc

│ └── main.cpython-36.pyc

├── logs

│ └── rainlog.log

├── middleware

│ ├── __pycache__

│ │ └── rainmiddleware.cpython-36.pyc

│ └── rainmiddleware.py

├── module

│ ├── __pycache__

│ │ └── rainmoduleuser.cpython-36.pyc

│ └── rainmoduleuser.py

├── nohup.out

├── python

│ └── info.txt

├── raindb

│ ├── bin

│ │ └── raindb-shell

│ ├── data

│ │ └── rain

│ │ └── rainmoduleuser.rdb

│ └── logs

│ └── rain

│ └── rainmoduleuser.log

├── register

│ └── rainregister.py

25 directories, 30 files

#!./python/bin/python3

import os

import sys

import logging

from flask import flask, request

from controller.raincontroller import *

from middleware import rainmiddleware as ware

from config import rainconfig

@ware.rainenrollmentmw(request)

def enrollment():

return rainenrollment(request.json)

@ware.rainentrancemw(request)

def entrance():

return rainentrance(request.form.to_dict())

@ware.rainentergoinmw(request, "input_entergoin")

def entergoin():

return rainverifyinfo(request.form.to_dict())

def page_not_found(error):

return render_template('error.html', error=error), 404

def main(args):

if __name__ == '__main__':

main(sys.ar**[1])

專案部署當然是越簡單也好,把複雜的命令轉化為一條命令,或者乙個執行檔案,對使用者體驗好感度有很好的提公升。下面是本demo的使用方式:

total 56

drwxr-xr-x 3 root root 4096 jan 2 09:51 config

drwxr-xr-x 3 root root 4096 jan 2 09:52 controller

drwxr-xr-x 5 root root 4096 dec 20 22:13 file

drwxr-xr-x 2 root root 4096 dec 20 22:13 html

drwxr-xr-x 3 root root 4096 dec 27 19:07 lib

drwxr-xr-x 2 root root 4096 jan 10 16:59 logs

drwxr-xr-x 3 root root 4096 jan 2 09:53 middleware

drwxr-xr-x 3 root root 4096 jan 2 09:53 module

drwxr-xr-x 7 root root 4096 dec 20 20:58 python

drwxr-xr-x 5 root root 4096 dec 28 18:04 raindb

drwxr-xr-x 2 root root 4096 jan 2 09:56 register

root 788 1 0 2018 ? 00:02:39 /usr/bin/python -es /usr/sbin/tuned -l -p

root 30587 29281 0 17:00 pts/0 00:00:00 grep --color=auto python

root 788 1 0 2018 ? 00:02:39 /usr/bin/python -es /usr/sbin/tuned -l -p

root 30613 29281 0 17:00 pts/0 00:00:00 grep --color=auto python

root 788 1 0 2018 ? 00:02:39 /usr/bin/python -es /usr/sbin/tuned -l -p

root 30649 29281 0 17:00 pts/0 00:00:00 grep --color=auto python

#!/bin/bash

port=$1

if [ ! $port ];then

port=8001

fifunction start()

unset date

fienterprt=$"\n"

echo $

nohup ./$ &

enterprint=$(echo -e $enterprt)

echo $enterprint

unset enterprt

unset enterprint

}function verify()" | grep -v grep`

if [[ -z $process ]];then

return 1

else

return 0fi}

verify

if [ $? -eq 0 ];then

exit 1

fistart

verify

if [ ! $? -eq 0 ];then

exit 2

else

fiunset processinfo

flask應用框架

flask是乙個用python編寫的web應用程式微型框架,基於werkzeug wsgi工具包和jinja2模板引擎。werkzeug是乙個wsgi web server gateway inte ce,web伺服器閘道器介面wsgi 工具包,實現了請求 響應物件等,用於構建web框架。jinja...

python Web應用框架之Flask

pip install flask 以下是乙個簡單的flask應用 from flask import flask def hello world return hello world if name main 執行 python hello.py running on首先,我們匯入了 flask ...

Flask例項應用及載入配置

from flask import flask 專案例項應用物件 flask類的例項化引數 import name flask程式所在的包 模組 傳 name 就可以 其可以決定 flask 在訪問靜態檔案時查詢的路徑 static path 靜態檔案儲存訪問路徑 不推薦使用,使用 static u...