【发布时间】:2009-12-17 22:14:28
【问题描述】:
我正在尝试使用带有cherrypy 的XML/SWF 图表库。我想生成带有漂亮图表的 html 报告。
我正在尝试使用cherryPy 公开XML/SWF 图表的默认示例之一,但由于某种原因,javascript 无法与cherryPy 一起正常工作。
我创建了以下 python 脚本:
import os.path
import os.path
import cherrypy
import os
class index:
def index(self):
return open('sample.html', 'r')
index.exposed = True
if name == 'main':
current_dir = os.path.dirname(os.path.abspath(file))
print current_dir
print os.path.join(current_dir, 'data', 'scripts', 'AC_RunActiveContent.js')
# Set up site-wide config first so we get a log if errors occur.
cherrypy.config.update({'environment': 'production',
'log.error_file': 'site.log',
'log.screen': True})
conf = {'/js/AC_RunActiveContent.js': {'tools.staticfile.on': True,
'tools.staticfile.filename': os.path.join(current_dir, 'data', 'scripts', 'AC_RunActiveContent.js')}}
cherrypy.quickstart(index(), '/', config=conf)
我的目录结构如下:
D:.
+---charts_library
+---data
¦ +---css
¦ +---scripts
+---resources
+---button_rollover
+---chart_in_swf
+---cursor
+---full_screen
+---preview_scroll
+---scroll
我将 javascript 文件和库所需的所有文件放在 .\data\scripts 文件夹中。 (我也尝试将这些文件放在根文件夹中,但也没有用)
示例 html 文件如下所示:
<HTML>
<script language="javascript">AC_FL_RunContent = 0;</script>
<script language="javascript"> DetectFlashVer = 0; </script>
<script src="AC_RunActiveContent.js" language="javascript"></script>
<script language="JavaScript" type="text/javascript">
<!--
var requiredMajorVersion = 9;
var requiredMinorVersion = 0;
var requiredRevision = 45;
-->
</script>
<BODY bgcolor="#FFFFFF">
<script language="JavaScript" type="text/javascript">
<!--
if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
alert("This page requires AC_RunActiveContent.js.");
} else {
var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
if(hasRightVersion) {
AC_FL_RunContent(
'codebase', 'http: //download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0',
'width', '400',
'height', '250',
'scale', 'noscale',
'salign', 'TL',
'bgcolor', '#777788',
'wmode', 'opaque',
'movie', 'charts',
'src', 'charts',
'FlashVars', 'library_path=charts_library&xml_source=sample.xml',
'id', 'my_chart',
'name', 'my_chart',
'menu', 'true',
'allowFullScreen', 'true',
'allowScriptAccess','sameDomain',
'quality', 'high',
'align', 'middle',
'pluginspage', 'http: //www.macromedia.com/go/getflashplayer',
'play', 'true',
'devicefont', 'false'
);
} else {
var alternateContent = 'This content requires the Adobe Flash Player. '
+ '<u><a href=http: //www.macromedia.com/go/getflash/>Get Flash</a></u>.';
document.write(alternateContent);
}
}
// -->
</script>
<noscript>
<P>This content requires JavaScript.</P>
</noscript>
</BODY>
</HTML>
当我双击示例文件时,它工作正常,但是当我运行 python 脚本并浏览到端口 8080 上的本地主机地址时,会不断出现一个弹出窗口,其中显示以下消息:
"此页面需要 AC_RunActiveContent.js"
我认为我在我的 python 脚本中做错了,但我无法找出我做错了什么。 为什么在 sample.html 文件中工作时,javascript 不能在cherryPy 中工作?我是不是忘记了什么?
【问题讨论】:
标签: javascript python cherrypy xml-swf-charts