映身網(wǎng)絡(luò)文件夾
1、按下圖指引映射魯班貓的samba文件夾
2、我們映射為Z盤:
2、用VScode 選擇剛才我們新映射的盤:
創(chuàng)建工程文件
新建目錄與文件如下:
工程初始代碼:
1、index.py 用于處理路由index,這里先給返回首頁index.html
import tornado.web
from tornado.web import RequestHandler
class IndexHandler(RequestHandler):
def get(self):
self.render("index.html")
2、index.html:
html>
html>
head>
meta charset="utf-8">
title>魯班貓監(jiān)控span class="hljs-name"title>
span class="hljs-name"head>
body>
h1>魯班貓監(jiān)控span class="hljs-name"h1>
span class="hljs-name"body>
span class="hljs-name"html>
3、 urls.py 此文件用于處理路由表
from views.index import IndexHandler as app_index
admin_urls = [
(r"/", app_index),
]
urls = admin_urls
4、config.py 這個文件主要用于配置靜態(tài)文件、模板文件路徑以及端口等
import os
root_path = os.path.dirname(__file__)
options = {
"port": 9000
}
configs = dict(
debug=False,
static_path=os.path.join(root_path, 'static'),
template_path=os.path.join(root_path, 'templates'),
)
5、application.py 用創(chuàng)建服務(wù)
import tornado.web
import tornado.ioloop
import tornado.options
import tornado.httpserver
from tornado.options import options, define
from config import options, configs
from urls import urls
define('port', type=int, default=9000, help="RUN_PORT")
class CustomApplication(tornado.web.Application):
def __init__(self, urls, configs):
settings = configs
handlers = urls
super(CustomApplication, self).__init__(handlers, **settings)
def creat_server():
print("starting server")
tornado.options.parse_command_line()
http_server = tornado.httpserver.HTTPServer(
CustomApplication(urls, configs)
)
http_server.listen(options["port"])
tornado.ioloop.IOLoop.instance().start()
6、main.py,主程序,用于啟動服務(wù)
from application import creat_server
if __name__ == "__main__":
creat_server()
至此,整個tornado工程創(chuàng)建完畢,我們在服務(wù)器上啟動服務(wù):
cat@lubancat:~/lugl/my_project$ python3 main.py
starting server
[I 230426 13:00:40 web:2239] 200 GET / (192.168.3.192) 13.93ms
在瀏覽器中打開:192.168.3.105:9000,打開頁面如下:
這樣我們的tornado工程就創(chuàng)建完成了,后面我將在此基于上增加自己想要的模塊就OK了。
我把基礎(chǔ)工程上傳到附件,大家可以測試一下。
審核編輯:湯梓紅
-
門禁系統(tǒng)
+關(guān)注
關(guān)注
17文章
392瀏覽量
45616 -
文件
+關(guān)注
關(guān)注
1文章
571瀏覽量
24835 -
Tornado
+關(guān)注
關(guān)注
0文章
16瀏覽量
9594 -
vscode
+關(guān)注
關(guān)注
1文章
157瀏覽量
7879
發(fā)布評論請先 登錄
相關(guān)推薦
評論