【问题标题】:XML/SWF charts example not working with cherryPyXML/SWF 图表示例不适用于cherryPy
【发布时间】: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


    【解决方案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 也可以使用 &lt;HEAD&gt; 元素。

    【讨论】:

    • 感谢您的回答。 javascript现在正在工作。我遇到了另一个问题。图表不显示。我只在页面上看到一个灰色框。我是否也应该将 XML 文件和 SWF 文件放在 conf 中?
    • 我对Flash小工具一无所知。阅读文档,并尝试自己调试。您似乎也需要从服务器提供 xml 配置。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-04
    • 2015-05-26
    • 2021-03-23
    • 1970-01-01
    • 2018-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多