Bottle实例1——HelloWord

本文通过两个示例介绍了如何使用Bottle Python Web框架创建简单的Web应用。第一个示例展示了如何通过从模块导入特定功能来设置路由,第二个示例推荐了使用import语句导入整个模块以避免名称冲突并提高代码可读性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这里只是记录个人学习轨迹,体会,无它!详细说明可能以后会补上!

在IDLE中编辑代码如下:

1、代码实例1:

1
2
3
4
5
6
7
8
9
10
11
# -*- coding:  utf-8 -*-
#!/usr/bin/python
# FileName: HelloWorld.py

from bottle  import route, run

@route( '/ttt')
def hello():
     return  "Welcome to the Bottle World of Python!"

run(host= 'localhost', port= 8080, debug= True)

按F5或者Run->Run module选项可以得到如下信息:

在浏览器中输入:http://localhost:8080/ttt

则会显示如下:

2、代码实例2:

为了使程序更加易读且避免名称的冲突,导入模块(module)是我们应该尽量避免from...import...而使用import语句。如下:

1
2
3
4
5
6
import bottle
@bottle.route( '/')
def hello():
     return  "Welcome to the Bottle World of Python!"

bottle.run(host= 'localhost', port= 8080, debug= True)

在浏览器中输入:http://localhost:8080    (注意没有"/ttt")  会得到同样的结果。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值