# encoding=utf-8 from flask import Flask app = Flask(__name__) @app.route("/task/") def task_list(): return "List of all task" @app.route("/task/<int:task_id>/") def task_detail(task_id): return "Detail of task#{}.".format(task_id) @app.route("/task/<int:task_id>/edit/",methods=[‘GET‘,‘POST‘]) def task_edit(task_id): return ‘From to edit task#{}.‘.format(task_id) @app.route("/task/create/",methods=[‘GET‘,‘POST‘]) def task_create(): return "Create New Task" @app.route("/task/<int:task_id>/delete/",methods=[‘DELETE‘]) def task_delete(task_id): raise NotImplementedError(‘DELETE‘)
# encoding=utf-8 from flask import Flask from flask import url_for app = Flask(__name__) @app.route("/task/<int:task_id>/edit/",methods=[‘GET‘,‘POST‘]) def task_edit(task_id): return ‘From to edit task#{}.‘.format(task_id) @app.route(‘/task/<int:task_id>/‘) def task_detail(task_id): edit_url = url_for(‘task_edit‘,task_id=task_id) return edit_url
# encoding=utf-8 from flask import Flask from flask import url_for app = Flask(__name__) @app.route("/task/<int:task_id>/edit/",methods=[‘GET‘,‘POST‘],endpoint=‘aliasname‘) def task_edit(task_id): return ‘From to edit task#{}.‘.format(task_id) @app.route(‘/task/<int:task_id>/‘) def task_detail(task_id): edit_url = url_for(‘aliasname‘,task_id=task_id) return edit_url
# encoding=utf-8 from flask import Flask from flask import url_for,render_template from werkzeug.routing import BaseConverter class ListConverter(BaseConverter): def to_python(self, value): return value.split(‘,‘) def to_url(self, values): return ‘,‘.join(BaseConverter.to_url(value) for value in values) app = Flask(__name__) app.url_map.converters[‘list‘] = ListConverter @app.route("/list/<list:data>/") def test_list(data): return ‘‘.join(data)
本文出自 “专注linux” 博客,请务必保留此出处http://forlinux.blog.51cto.com/8001278/1420970
原文地址:http://forlinux.blog.51cto.com/8001278/1420970