python flask

9-01 993 views

http://flask.pocoo.org/docs/0.12/quickstart/#routing

import flask
import re
import os
import utils
import mimetypes

fileMapping = {
'^index$':                    "index.html",
'^index/$':                   "index.html",
'^login$':                    "index.html",
'^login/$':                   "index.html",
'^login.html$':               "index.html",
'^index.html$':               "index.html",
'^index/filesDetails/?.*$':   "index.html",
'^index/uploadFailed/?.*$':   "index.html",
'^index/uploading/?.*$':      "index.html",
'^index/downLoadFailed/?.*$': "index.html",
'^index/downLoading/?.*$':    "index.html",
'^index/uploaded/?.*$':       "index.html",
'^index/downLoaded/?.*$':     "index.html",

'^admin$':                 "admin/index.html",
'^admin/$':                "admin/index.html",
'^admin/login/?.*$':       "admin/index.html",
'^admin/dashboard/?.*$':   "admin/index.html",
'^admin/users/?.*$':       "admin/index.html",
'^admin/user_edit/?.*$':   "admin/index.html",
'^admin/admins/?.*$':      "admin/index.html",
'^admin/admin_edit/?.*$':  "admin/index.html",
'^admin/servers/?.*$':     "admin/index.html",
'^admin/server_edit/?.*$': "admin/index.html",
'^admin/assigns/?.*$':     "admin/index.html",
'^admin/assign_edit/?.*$': "admin/index.html"
}

app = flask.Flask(__name__)

@app.route('/api')
def api():
    return 'api interface'

@app.route('/<path:dummy>')
def fallback(dummy):
    print flask.request.path
    return staticFile(flask.request)

def staticFile(request = None):
    file = request.path

    if file[0] == '/' :
        file = file[1:]

    for pattern in fileMapping :
        if re.match(pattern, file) :
            file = fileMapping[pattern]
            break

    if file == '' or file == '/':
        file = 'index.html'

    # file = os.path.abspath(utils.curdir() + '/static/' + file)
    file = 'static/' + file

    # mime = mimetypes.guess_type(file, strict=True)

    return flask.send_file(file)

@app.errorhandler(404)
def page_not_found(e):
    print '404: ', flask.request.path
    flask.redirect(flask.url_for('/'))
    return

if __name__ == '__main__':
    # app.debug = True
    app.run(host='0.0.0.0', port=5200)

OpenCV-Python

OpenCV-Python OpenCV-Python Installing OpenCV from prebuilt binaries Below Python packages are to be downloaded and installed to their default lo...

阅读全文

Python 乱码解决

''.decode(sys.getfilesystemencoding())

阅读全文

python hideconsole

def hideConcole(): import ctypes kernel32 = ctypes.WinDLL('kernel32') user32 = ctypes.WinDLL('user32') SW_HIDE = 0 hWnd = k...

阅读全文

欢迎留言