English 中文(简体)
XML/SWF charts example not working with cherryPy
原标题:

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 .datascripts 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?

问题回答
conf = { /js/AC_RunActiveContent.js :
    { tools.staticfile.on : True,
      tools.staticfile.filename :
         os.path.join(current_dir,  data ,  scripts ,  AC_RunActiveContent.js )}}

And later

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

My bet is the latter produces a 404. Try changing the line to:

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

Oh, and also your HTML could use a <HEAD> element.





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签