저는 파이썬 기반의 웹 서버를 구축하고 있습니다. ( 예, 파이썬은 웹 서버에 대한 나쁜 선택입니다. 그러나 이것은 내가 가지고있는 유일한 선택입니다. PHP, 하지만 난 baseHTTPserver는 자바 스크립트 라이브러리를 사용할 수 없습니다.
다음 코드 조각은
당신이 만약 (내가 옆에 추출 된 protovis 라이브러리를 가지고 제공) 작동 나는 baseHTTPserver에 위의 코드를 반환 할 경우는, 그러나 여기 https://github.com/mbostock/protovis/zipball/v3.3.1
<html>
<head>
<title>Area Chart</title>
<link type="text/css" rel="stylesheet" href="ex.css?3.2"/>
<script type="text/javascript" src="protovis/protovis.js"></script>
<style type="text/css">
#fig {
width: 430px;
height: 225px;
}
</style>
</head>
<body>
<div id="center">
<div id="fig">
<script type="text/javascript+protovis">
var data = pv.range(0, 10, .1).map(function(x) {
return {x: x, y: Math.sin(x) + Math.random() * .5 + 2};
});
/* Sizing and scales. */
var w = 400,
h = 200,
x = pv.Scale.linear(data, function(d) d.x).range(0, w),
y = pv.Scale.linear(0, 4).range(0, h);
/* The root panel. */
var vis = new pv.Panel()
.width(w)
.height(h)
.bottom(20)
.left(20)
.right(10)
.top(5);
/* Y-axis and ticks. */
vis.add(pv.Rule)
.data(y.ticks(5))
.bottom(y)
.strokeStyle(function(d) d ? "#eee" : "#000")
.anchor("left").add(pv.Label)
.text(y.tickFormat);
/* X-axis and ticks. */
vis.add(pv.Rule)
.data(x.ticks())
.visible(function(d) d)
.left(x)
.bottom(-5)
.height(5)
.anchor("bottom").add(pv.Label)
.text(x.tickFormat);
/* The area with top line. */
vis.add(pv.Area)
.data(data)
.bottom(1)
.left(function(d) x(d.x))
.height(function(d) y(d.y))
.fillStyle("rgb(121,173,210)")
.anchor("top").add(pv.Line)
.lineWidth(3);
vis.render();
</script>
</div>
</div>
</body>
</html>
를 얻을 시도하려는, 작동하지 않는 것. 내 조사에서 "protovis/protovis.js"의 라이브러리가 제대로 포함되지 않은 것 같습니다.
if url[0] == "/chart":
self.send_response(200)
self.send_header("Content-type","text/html")
self.end_headers()
self.wfile.write(chart())
return
여기서 chart() 함수는 위의 행을 반환합니다.
내가 파이썬 2.6에 CentOS 6.2에서하고 있어요, 나는 내가 사용하는 자바 스크립트 라이브러리 것을 포함 baseHTTPserver에서해야 할 특별한 있나요? 동일한 코드가 아파치 + PHP와 잘 작동했는데, 간단히 반향한다.
아이디어가 있으십니까?
======================== 솔루션 ===================== ===
Apache + PHP와 달리 BaseHTTPServer는 사용자가 해당 폴더에 넣은 것만 제공하지 않습니다. Matthew가 설명했듯이 직접 해보거나 다른 서버에서 protovis.js를 제공해야합니다 (다른 포트에서 실행되는 SimpleHTTPServer 일 수도 있음). - Vasiliy Faronov
내가 문제를 해결하기 위해해야 할 일을했을 무엇
아래
마태 복음 아담스의 명령은 자바 스크립트
if url[0] == "/protovis/protovis.js":
f = open("protovis/protovis.js","rb")
for each_line in f:
self.wfile.write(each_line)
return
있는 해결할 수있는 문제를 파일 처리 do_GET()로 다른 방법을 추가했다 문제.
나는 정말
다음과 같이 설정해야합니까? '