0

I am trying to use use the XML/SWF Charts library with cherrypy. I want to generate html reports with nice looking charts.

I am trying to expose one of the default examples of XML/SWF charts with cherryPy, but for some reason the javascript is not working properly with cherryPy.

I created the following python script:

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)

I have the following directory structure:


D:.
+---charts_library
+---data
¦   +---css
¦   +---scripts
+---resources
    +---button_rollover
    +---chart_in_swf
    +---cursor
    +---full_screen
    +---preview_scroll
    +---scroll

I put the javascript file and all files needed by the library in the .\data\scripts folder. (I also tried to put these files in the root folder but that didn't work either)

the sample html file looks as follows:


<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>

When I double click the sample file it works fine but when I run the python script and browse to the local host address on port 8080 then a popup keeps occuring which shows the following message:

"This page requires AC_RunActiveContent.js"

I think I did something wrong in my python script but I am not able to find out what I did wrong. Why is the javascript not working in cherryPy while it does work in the sample.html file? Did I forget something?

4

1 回答 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>元素。

于 2009-12-17T22:24:14.577 回答