時間:2024-02-02 15:00:01 | 來源:網(wǎng)站運營
時間:2024-02-02 15:00:01 來源:網(wǎng)站運營
如何使用Python搭建一個OA網(wǎng)站?:1、學習一種web框架python -m pip install tornado
接下來,新建一個普通的python項目,并需要生成一些文件及文件夾,主要包括如下:from url import urlimport tornado.webimport ossettings = dict( template_path = os.path.join(os.path.dirname(__file__), "templates"), static_path = os.path.join(os.path.dirname(__file__), "statics"), debug=True #生產(chǎn)環(huán)境去掉 )application = tornado.web.Application( handlers = url, **settings )
2、server.py#!/usr/bin/env Python# coding=utf-8import tornado.ioloopimport tornado.optionsimport tornado.httpserverfrom application import applicationfrom tornado.options import define, optionsimport settingsdefine("port", default = 80, help = "run on the given port", type = int)def main(): #啟動網(wǎng)站進程 tornado.options.parse_command_line() http_server = tornado.httpserver.HTTPServer(application) http_server.listen(options.port) host='127.0.0.1'; print ("Development server is running at http://%s:%s" % (host,options.port)) print ("Quit the server with Control-C") loop=tornado.ioloop.IOLoop.instance(); tornado.autoreload.start(loop); #更改代碼無需重啟時需要,只在開發(fā)環(huán)境 loop.start();if __name__ == "__main__": main()
3、url.py#!/usr/bin/env Python# coding=utf-8"""the url structure of website"""import sys #utf-8,兼容漢字from importlib import reloadreload(sys)from handlers.index import IndexHandlerurl = [ #網(wǎng)站各項功能 (r'/', IndexHandler) ]
說明:通過URL路徑’/’,訪問IndexHandler對應的HTML文件,通過上方import目錄可以看到,這個文件在handlers文件夾里。關鍵詞:使用
微信公眾號
版權所有? 億企邦 1997-2025 保留一切法律許可權利。