XML / SWF图表示例不适用于cherryPy

时间:2009-12-17 22:14:28

标签: javascript python cherrypy xml-swf-charts

我正在尝试使用带有cherrypy的XML / SWF Charts库。我想用漂亮的图表生成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)

我有以下目录结构:

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)

我将javascript文件和库所需的所有文件放在。\ data \ scripts文件夹中。 (我也尝试将这些文件放在根文件夹中,但这也不起作用)

示例html文件如下所示:


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

当我双击示例文件时,它工作正常,但是当我运行python脚本并浏览到端口8080上的本地主机地址时,会弹出一个弹出窗口,显示以下消息:

“此页面需要AC_RunActiveContent.js”

我认为我在python脚本中做错了但是我无法找出我做错了什么。 为什么javascript在cherryPy中不起作用,而它在sample.html文件中有效?我忘了什么吗?

1 个答案:

答案 0 :(得分: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>元素。