使⽤python+tornado做项⽬demo演⽰模板
很简单,可是却也折腾了不是时间,⾛了不少弯路。在此备注记录⼀下,以供后需。
# web_server.py
#!/usr/bin/env python
# coding=utf-8
import os.path
import tornado.httpserver
import tornado.options
diameter可数吗import tornado.web
from auto_gen_jd import AutoGenJD
from jd_parser import JdParser
from tornado.options import define,options
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
address函数有什么用define("port",default = 8086,help="run on the given port",type=int)
class IndexHandler(tornado.web.RequestHandler):
def get(self):
result = _argument("result",[])
num = _argument("num",5)
source_text = _argument("source","")
def post(self):
result = _argument("result",[])
source_text = _argument("source","")
num = _argument("num",5).encode("utf-8")
result = _jd_with_kmeans(source_text,num)
class GenJdHandler(tornado.web.RequestHandler):
def get(self):
result = _argument("result",[])
num = _argument("num",5)
source_text = _argument("source","")
def post(self):
result = _argument("result",[])
source_text = _argument("source","")
num = _argument("num",5).encode("utf-8")
result = _jd_with_kmeans(source_text,num)
class JdParserHandler(tornado.web.RequestHandler):
def get(self):
result = _argument("result",[])
source_text = _argument("source","")
def post(self):
source_text = _argument("source","")
result = extr.split_multi_jd(source_text)
if__name__ == "__main__":
genjd = AutoGenJD()
extr = JdParser()
tornado.options.parse_command_line()
app = tornado.web.Application(
violin读音发音
handlers = [(r'/',IndexHandler),(r'/genjd',GenJdHandler),(r'/jdparser',JdParserHandler)],
template_path = os.path.join(os.path.dirname(__file__),"templates"),
debug=True,
autoescape=None,
)
print""
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
模板⽂件,共有四个,⼤体雷同:
outputjd.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" >
<title>技能在线抽取</title>
<link rel = "stylesheet" href="/amazeui/2.4.0/css/amazeui.min.css">
<link rel = "icon" href="head.ico" >
京东python入门教程<script>
function get_result(){
return true
}
</script>
</head>
<body>
{% autoescape None %}
<div class="am-topbar">
<h1 class="am-active">在线演⽰</h1>
</div>
<div class="am-g">
<div class="am-u-sm-7 am-u-sm-centered">
<div class="am-intro-left am-active" >
<label ><em>使⽤说明</em></label>
<p class="am-serif">粘贴企业招聘信息到⽂本框,再点击提交,可获得jd解析结果。<a href="/genjd" title="⾃动⽣成JD">⾃动⽣成JD</a></p><br />
</div>
<form class="am-form am-form-horizontal" role="form" action="/jdparser" method="post" onsubmit="return get_result()">
<textarea class="am-form-field am-radius" name="source" rows="20" cols="110" placeholder="input job description here" autofocus="True" >{{source}}</textarea>                <div class="am-u-sm-centered" >
<button type="submit" onclick="get_result()"class="am-btn am-btn-primary" value="提交">submit</button>
</div>
</form>
</div>
<br />
<div class="am-u-sm-6 am-u-sm-centered">
<div id='res_hint'></div>
<div id="result">
{% for i,jd in enumerate(result,1) %}
<br /> jd #{{ i }}==================== <br />
{%
set hint = {'sex':'年龄','cert':"证书","pay":"薪酬","job_tag":"职业标注","inc_tag":"公司标注","inc_name":"公司标注","demand":"⼯作要求","duty":"⼯作内容","benefits":"福利待遇","other":"其它未处理的句⼦","pub_time":"发布时间","        %}
<ul>
{% for k,v in jd.iteritems() %}
{% if k=="demand"or k=="duty"or k=="benefits"or k=="other" %}
<li title={{hint[k]}}>{{k}}: <pre>{{ v }} </pre></li>
{% else %}
<li title={{k}}>{{k}} :<pre/> {%raw v %}</pre></li>
{% end %}{% end %}{% end %}
</ul>
</div>
<script type="text/javascript" src="/amazeui/2.4.0/js/amazeui.min.js"</script>
</body>
</html>
outputgen.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" >
<title>⾃动⽣成JD</title>
<link rel = "stylesheet" href="/amazeui/2.4.0/css/amazeui.min.css">
<link rel = "icon" href="head.ico" >
<script>
function get_result(){
dubbo admin nacos
num = ElementById("num").value;
jobname = ElementById("jobname").value;
vb通用对话框return true
}
</script>
</head>
<body>
<div class="am-topbar">
<h1 class="am-active">在线演⽰</h1>
</div>
<div class="am-g">
<div class="am-u-sm-6 am-u-sm-centered">
<div class="am-intro-left" >
<label class="am-active"><em>使⽤说明</em></label>
<p class="am-serif">输⼊职位名和所需⽣成jd句⼦数,再点击提交,可获得jd结果。</p><br />
</div>
<form class="am-form-inline" role="form" action="/genjd" method="post" onsubmit="return get_result()">
<input id="jobname"class="am-form-field am-radius" type="text" name="source" placeholder="input jobname here" autofocus="True" value={{source}}></input>
<input id="num"class="am-form-field am-round" type="number" min="1" max="50" name="num" title="input number of sententces" value={{num}}></input>
<button type="submit" onclick="get_result()"class="am-btn am-btn-primary" value="提交">submit</button>
</form>
</div>
<br />
<div class="am-u-sm-6 am-u-sm-centered">
<div id='res_hint'class="am-active">⽣成结果: <a href="/jdparser" title="jd解析">JD解析</a></div>
<div id="result" >
<ul >
{% for i,s in enumerate(result) %}
<li>{{i+1}}. {{s}} </li>
{%end%}
</ul>
</div>
<script type="text/javascript" src="/amazeui/2.4.0/js/amazeui.min.js"></script>
</body>
</html>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。