首页 编程 Python 查看内容

Python的Web框架之CherryPy的介绍、安装、基本使用

2020-5-26 12:51 |来自: 互联网 3014 0

摘要: 1 CherryPy:=========1.1 是一种用于Python的、简单而非常有用的Web框架。1.2 可以运行在最新版本的Python、Jython、Android上。1.3 其主要作用是以尽可能少的操作将Web服务器与Python代码连接。1.4 是 CGI 的优秀替代品,并且是创建 Python Web 应用程序的良好基础。2 环境:=====华为笔记本电脑,深 ...
关键词: CherryPy WARNING script Python PATH HelloWorld directory installed location suppress

1 CherryPy:

=========

1.1 是一种用于Python的、简单而非常有用的Web框架。

1.2 可以运行在最新版本的Python、Jython、Android上。

1.3 其主要作用是以尽可能少的操作将Web服务器与Python代码连接。

1.4 是 CGI 的优秀替代品,并且是创建 Python Web 应用程序的良好基础。


2 环境:

=====

华为笔记本电脑,深度deepin-linux操作系统,python3.8,微软vscode编辑器,谷歌浏览器。


3 官网:

=====

安装
pip install CherryPy
#本机安装
#sudo pip3.8 install CherryPy #有点慢,放弃
sudo pip3.8 install -i https://mirrors.aliyun.com/pypi/simple CherryPy #超快

4 安装:

=====

  WARNING: The script calc-prorate is installed in '/usr/local/python3.8/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script cheroot is installed in '/usr/local/python3.8/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script cherryd is installed in '/usr/local/python3.8/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

提醒:没有设置路径,暂时不管,估计没有设置软连接。

  WARNING: The script calc-prorate is installed in '/usr/local/python3.8/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script cheroot is installed in '/usr/local/python3.8/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script cherryd is installed in '/usr/local/python3.8/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

5 hello world:

5.1 方法一,代码:

import cherrypy
class HelloWorld(object):
@cherrypy.expose
def index(self):
return "Hello World!"
cherrypy.quickstart(HelloWorld())

运行示范:

5.2 方法二,代码:

import cherrypy  
class HelloWorld:
def index(self):
return "Hello world!"
index.exposed = True #暴露设置为true,区别
cherrypy.quickstart(HelloWorld())

5.3 方法三,代码:

import cherrypy
class HelloWorld(object):
@cherrypy.expose
def index(self):
return "Hello world!"
if __name__ == '__main__':
cherrypy.quickstart(HelloWorld())

6 显示html的plotly的柱状图法

import cherrypy
class HtmlShow(object):
@cherrypy.expose
def index(self):
return """
t
tt
ttJavascript与Plotly结合的可视化作图
t
t
tt

t
t
t
t

"""

if __name__ == '__main__':
cherrypy.quickstart(HtmlShow())


===整理并分享===

喜欢就点赞、转发和收藏。

自己可以继续深入学习。

本文出处: https://www.toutiao.com/a6830938569767387661/
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

最新评论

返回顶部