1
我期待分享Python環境變量信息,以Java腳本中的CherryPy如下:共享變量信息
class test(object):
@cherrypy.expose
def index(self):
variableX = 2016
return """<!DOCTYPE html>
<html>
<head>
<title>Set interval with two inputs</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<link rel="stylesheet" type="text/css" href="/static/codebase/dhtmlxcalendar.css"/>
<script src="/static/codebase/dhtmlxcalendar.js"></script>
<style>
input#date_from, input#date_to {
font-family: Tahoma;
font-size: 12px;
background-color: #fafafa;
border: #c0c0c0 1px solid;
width: 100px;
}
span.label {
font-family: Tahoma;
font-size: 12px;
}
</style>
<script>
var myCalendar;
function doOnLoad() {
myCalendar = new dhtmlXCalendarObject(["date_from","date_to"]);
// getting today info (start code)
var tomm = new Date();
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10) {dd='0'+dd};
if(mm<10) {mm='0'+mm};
today = yyyy+'-'+mm+'-'+dd;
// getting today info (end code)
myCalendar.setDate(today);
myCalendar.hideTime();
// init values
var t = new Date();
byId("date_from").value = variableX ;
byId("date_to").value = variableX ;
}
function setSens(id, k) {
// update range
if (k == "min") {
myCalendar.setSensitiveRange(byId(id).value, null);
} else {
myCalendar.setSensitiveRange(null, byId(id).value);
}
}
function byId(id) {
return document.getElementById(id);
}
</script>
</head>
<body onload="doOnLoad();">
<form method="get" action="generate">
<div style="position:relative;height:280px;">
<span class="label">From</span> <input type="text" id="date_from" name="FirstDate" onclick="setSens('date_to', 'max');" readonly="true">
<span class="label">Till</span> <input type="text" id="date_to" name="LastDate" onclick="setSens('date_from', 'min');" readonly="true">
<button type="submit">Give it now!</button>
</form>
</div>
</body>
</html>"""
我試圖讓variableX(這是2016年價值)在html內的javascript內部。任何想法?
謝謝,它工作。我會看看Jinja2。再次感謝您的回答 – test3321
如果變量X是一個列表(例如:[[[5,「one」],[8「two」]]')。 它不會處理。它給出:'TypeError:不能連接'str'和'list'對象' 任何想法? @jordeu – test3321
是的,使用jinja2 – jordeu