XML/SWF图表示例在cherryPy中无法工作

0 投票
1 回答
1052 浏览
提问于 2025-04-15 17:09

我正在尝试用XML/SWF Charts库和cherrypy来生成漂亮的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') # 首先设置全站的配置,这样如果出现错误就能记录日志。 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脚本可能哪里写错了,但我找不到问题出在哪里。为什么JavaScript在cherryPy中不工作,而在sample.html文件中却能正常运行?我是不是漏掉了什么?

1 个回答

1
conf = {'/js/AC_RunActiveContent.js':
    {'tools.staticfile.on': True,
     'tools.staticfile.filename':
         os.path.join(current_dir, 'data', 'scripts', 'AC_RunActiveContent.js')}}

然后

<script src="AC_RunActiveContent.js" language="javascript"></script>

我猜后面的那个会产生404错误。试着把这一行改成:

<script src="/js/AC_RunActiveContent.js" language="javascript"></script>

哦,还有你的HTML里可以加一个 <HEAD> 元素。

撰写回答