flask开启debug模式的两种方法、加载配置文件的两种方法、URL传参的四种方法
from flask import Flask
app = Flask(__name__) # app.config.update(DEBUG=True)#开启debug模式 #加载配置文件方法一
# import config
# app.config.from_object(config)
# 加载配置文件方法二
app.config.from_pyfile('config.py') # 访问根目录的路径
@app.route('/')
def hello_world():
a = 1
b = 0
c = a / b
return c # 通过URL给后台传参的方法一
@app.route('/p/<article_id>/')
def article(article_id):
return '您当前阅读的是第%s篇文章' % article_id # 访问的URL:http://127.0.0.1:5000/p/2ss5/
# 页面结果:您当前阅读的是第2ss5篇文章 # <editor-fold desc="限制参数的类型"> # int型
@app.route('/article/<int:article_id>/')
def articles(article_id):
return '你当前阅读的是第%s篇文章' % article_id # 访问的URL为:http://127.0.0.1:5000/article/34/
# 页面结果是:你当前阅读的是第34篇文章
# 访问的URL:http://127.0.0.1:5000/p/2ss5/
# 页面结果:404找不到页面(报错)
# </editor-fold> # str型
@app.route('/<string:classfiy>/')
def classfiy(classfiy):
return '你当前的类目是%s'%classfiy
# 访问的URL:http://127.0.0.1:5000/shujuzu/
# 页面结果为:你当前的类目是shujuzu # @app.route('/123/')
# def hello_world():
# a = 1
# b = 0
# c = a / b
# return 'Hello World!'
if __name__ == '__main__':
app.run(debug=True) #开启debug模式
flask开启debug模式的两种方法、加载配置文件的两种方法、URL传参的四种方法的更多相关文章
- Django项目关闭debug模式后,静态文件无法加载的解决办法
开启内置服务器,由于项目中local_settings.py文件中的DEBUG=True,进行开发和调试一直没什么问题. 但是现在需要编写404,500等出错页面,在debug模式下出了错都会出现报错 ...
- Angular页面传参的四种方法
1. 基于ui-router的页面跳转传参 (1)在Angular的app.js中用ui-route定义路由,比如有两个页面, 一个页面(producers.html)放置了多个producers,点 ...
- angularJS 传参的四种方法 【修改】
1. 基于ui-router的页面跳转传参(1) 在AngularJS的app.js中用ui-router定义路由,比如现在有两个页面,一个页面(producers.html)放置了多个produce ...
- angularJS 传参的四种方法
AngularJS - Passing data between pages 著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处.作者:Ye Huang链接:https://www.z ...
- android 加载中、无网络、无数据、出错 四种状态的代码封装
package com.weavey.loading.lib;import android.content.Context;import android.content.res.TypedArray; ...
- 【python】flask 开启 debug 模式
方法一: 直接在run的时候添加debug from flask import Flask app = Flask(__name__) @app.route('/') def hello_world( ...
- mybatis 加载配置文件的两种方式
package com.atguigu.day03_mybaits.test; import java.io.IOException;import java.io.InputStream;import ...
- mybatis 加载配置文件的方法
一. 使用sqlSessionFactory 的 mapperLocations 进行加载 <!-- SessionFactory --> <bean id="sqlSe ...
- flask使用debug模式时,存在错误时,会占用设备内存直至服务重启才释放;debug模式会开启一个守护进程(daemon process)
函数调用顺序flask的app.py的run-->werkzeug的serving.py的run_simple-->调用werkzeug的debug的__init__.py里的类Debug ...
随机推荐
- js post跳转
function clickFunc(id) { var params = new Array(); params.push({ name: "id", value: id}); ...
- Entity FreamWork框架
实体框架 (Entity Framework) 1.是微软以ADO.Net为基础所发展出来的对象关系对应(O/R Mapping)解决方案. 2.实体框架Entity Framework是ADO.Ne ...
- .net core mvc 类库读取配置文件
appsettings.json,给类库项目引入 Microsoft.Extensions.Configuration 和 Microsoft.Extensions.Configuration.J ...
- 基于SSM框架配置多数据源
项目基于ssm + maven,通过注解可以实现自动切换数据源. 一.pom.xml <?xml version="1.0" encoding="UTF-8&quo ...
- Spring FactoryBean用法
最近在看spring ioc源码,看到FactoryBean这个内容.这个和BeanFactory的区别 1. BeanFactory: 生成bean的工厂,是一个接口,定义了很多方法 2. Fact ...
- frameset 在 Google Chrome 中无法隐藏左边栏解决方法!
使用Frameset 框架,发现在IE下, <frameset name="mainDefine" cols="200,10,*" frameborder ...
- sql: Oracle 11g create procedure
CREATE OR REPLACE PROCEDURE proc_Insert_BookKindList ( temTypeName nvarchar2, temParent int ) AS nco ...
- cf1088D. Ehab and another another xor problem(思维)
题意 题目链接 系统中有两个数\((a, b)\),请使用\(62\)以内次询问来确定出\((a, b)\) 每次可以询问两个数\((c, d)\) 若\(a \oplus c > b \opl ...
- vue指令示例合集
vue所有指令练习合集.这是个html文件,用chrome打开可查看结果. <!DOCTYPE html> <html lang="en" xmlns:v-on= ...
- RGB与INT类型的转换
开发时遇到的问题,设置图层样式时颜色的返回值是uint,一时不知改怎么转换为C#常用的RGB值了. 一番百度,结果如下: RGB = R + G * 256 + B * 256 * 256 因此可得到 ...