4

前端开发(和webpy后端联调)

 2 years ago
source link: https://feixiaoxing.blog.csdn.net/article/details/126447432
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

前端开发(和webpy后端联调)

嵌入式-老费 已于 2022-08-21 10:34:11 修改 44
分类专栏: 前端开发 文章标签: 前端

【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing @163.com】

        作为前端开发来说,一般需要和后端开发进行联调。而通常后端开发,都是和特定语言绑定在一起的。因此,选择一款简单的后端开发框架,对于前端开发来说是大有裨益的。webpy就是这样一个基于python的开发框架。如果项目本身工作量不大,用webpy实际部署到应用环境中也是可以的。

1、下载webpy

pip3 install web.py

2、确认webpy已经安装

3、copy第一个webpy程序



newCodeMoreWhite.png

4、执行脚本程序

5、打开网页,确认服务器已经running起来了

fcffa11e23af43359f1408de370b04d2.png

6、其他范例程序 

        在github上有很多的范例程序,比如blog、wiki、todo-list等等,都值得看一看,

GitHub - webpy/webpy-examples: example code for web.pyexample code for web.py. Contribute to webpy/webpy-examples development by creating an account on GitHub.fluidicon.pnghttps://github.com/webpy/webpy-examples/

7、blog范例解剖

        我们以blog程序举例,看看编写一个web后端需要做那些工作,

        1)找到blog代码地址,webpy-examples/blog at master · webpy/webpy-examples · GitHubexample code for web.py. Contribute to webpy/webpy-examples development by creating an account on GitHub.fluidicon.pnghttps://github.com/webpy/webpy-examples/tree/master/blog

        2)确认主要的文件,

1749084a5f82491d8e184014b64e4190.png

         3)分析各个文件用途

        templates/ 主要存放静态static文件,主要是html文件、css文件和js文件

        blog.py,web后端入口文件

        model.py,数据库操作文件

        schema.sql,数据库接口文件

        4) 拿navicat之类软件导入sql文件

        5)修改model.py中的数据库注册代码,注意根据自己本地配置添加passwd参数

db = web.database(dbn="mysql", db="blog", user="root")

        6)开始运行web

        7)查看web是否可以正常运行

39c3c10dc8ac436a922a9bf93d28137d.png

         8)其他的examples差不多也是这样的运行方法

8、webpy官网地址如下所示


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK