# Flask 路由系统 #
##
## 方法一:使用系统路由,在app.py中有个例子 ## ##
@app.route('/')
def index():
return ops_render("index/index.html")*
ops__render是我自己在render__template的基础上中封装的传参方法
from flask import g,render_template
import datetime
def ops_render( template,context = {}):
if 'current_user' in g:
context['current_user'] = g.current_user
return render_template(template,**context)
## 方法二:使用蓝图进行路由分离: ##
from flask import Blueprint
from common.libs.UserService.helper import ops_render
route_food = Blueprint( 'food_page',__name__ )
@route_food.route( "/index" )
def index():
return ops_render( "food/index.html" )
引入蓝图-定义蓝图名-根据蓝图名写路由
在app.py文件里
from controllers.food.Food import route_food
app.register_blueprint(route_food,url_prefix='/food')
url_prefix中填写统一路由名
**附:对路由统一管理:**
pytho方法
# -*- coding: utf-8 -*-
import time
class UrlManager(object):
def __init__(self):
pass
@staticmethod
def buildUrl( path ):
return path
@staticmethod
def buildStaticUrl(path):
ver = "%s"%( 22222222 )
path = "/static" + path + "?ver=" + ver
return UrlManager.buildUrl( path )
js方法
buildUrl:function( path,params){
var url = "" +path;
var _paraUrl = "";
if (params){
_paraUrl =object.keys( params ).map(function(k){
return[encodeURIComponent( k ),encodeURIComponent( params[k])].join("=")
}).join("&")
_paraUrl ="?"+_paraUrl
}
return url +_paraUrl;
$(document).ready( function() {
common_ops.init();
})
}
var x ={
}