【问题标题】:Flex 4 + Django: Testing and Release OptionsFlex 4 + Django:测试和发布选项
【发布时间】:2012-01-22 23:37:56
【问题描述】:
我正在创建一个基于 django 的站点,该站点将提供偶尔通过 pyamf 访问数据的 Flash 应用程序。我需要能够在 django 框架的上下文中轻松测试 flash,即使用所有登录 cookie 和所有可用的东西,以便当我进行 pyamf 调用时,它具有所有用户上下文。而且我需要能够测试和以理智的方式发布 swf 和包装器 html。然而:
- flex 中的 html 模板已经是模板,所以如果我将 django 的模板代码放在那里,它会在创建 flashapp.html 之前被刮掉。
- html 和 swf 会自动发布到同一个目录,但我希望它们转到不同的目录,因为 swf 不应该由 django 提供,并且 html 应该在 django 控制的区域中。
乍一看,这让我相信我需要:
- 一种将 html 和 swf 文件发布到不同位置的方法。 (我不知道该怎么做。)
- 一种将 html 作为存根(无 html/body 标记)发布的方法,以便我可以从 django 中的另一个位置包含它们。 (我想只是从 index.template.html 中删除我不想要的东西?)
- 然后我可以将 flex 指向 django 站点,该站点又包含生成的 flashapp.html,该 flashapp.html 又引用了 swf,它应该可以正常工作。 (我假设通过将备用 html 提供给运行/调试设置。)
所以我的问题归结为:
- 以上方法是最好的方法,还是正确的方向?
- 如果是这样,如何将 html 和 swf 发布到不同的目录? (对于调试和发布模式,如果有两种不同的方法。)
- 如果不是,什么是正确的?
如果在这个主题上对我有任何其他一般性的建议,请随时分享。 :-)
【问题讨论】:
标签:
django
apache-flex
release-management
pyamf
【解决方案1】:
我自己终于想通了。 this 和 django get-parameters 的组合有效。一般要点:
- 您可以毫无顾虑地将
{% tags %} 和{{ variables }} 放入index.template.html,因为没有办法像${title} 那样自定义当前存在的宏
- 如果您在项目的
html-template 目录中创建foo.template.html 和foo-debug.template.html,则前者将覆盖index.template.html 用于发布版本,而后者用于调试版本(请注意,结果将是 foo -debug.html 而不是 foo.html。)
- 您可以将 SWF 的名称作为参数传递给 django,然后让它为您填写目录
foo-debug.template.html
<object ...
<param name="movie" value="{{ bin_debug_url }}/${swf}.swf" ...
djangoflash.html
{% block content %}
{% include flash_template %}
{% endblock %}
views.py
def djangoflashview( request, **kwargs ):
if not kwargs.has_key('extra_context'):
kwargs['extra_context'] = {}
if request.GET.has_key('name'):
debug = "-debug" if request.GET.has_key('debug') else ""
bin_debug_dir = '/dir-to-bin-debug/'
bin_debug_url = 'url-to-bin-debug'
name = bin_debug_dir + request.GET['name'] + debug + '.html'
kwargs['extra_context']['flash_template'] = name
kwargs['extra_context']['bin_debug_url' ] = bin_debug_url
return direct_to_template( request, **kwargs )
urls.py
url( r'^djangoflash/', 'views.djangoflashview',
{ 'template': 'djangoflash.html' }
foo.mxml 的运行调试目标:
/url-to-django/djangoflash/?name=foo
调试 foo.mxml 时,flex:
- 在网址中添加
&debug=true
- 打开浏览器到
/url-to-djangoflash/djangoflash/?name=foo&debug=true
- 在
urls.py 中选择djangoflash/
- 将请求传递给
djangoflashview 和{'name':'foo','debug':'true'} 到request.GET in views.py
- 计算出
foo-debug.html 位置的名称和位置,并将其传递给flash_template 上下文变量
- 以及
bin_debug_url上下文变量的swf的url
- 并加载直接模板
djangoflash.html
- 在
djangoflash.html 中,包括使用flash_template 上下文变量的闪存的foo-debug.html 包装器
- 然后填充
bin_debug_url 上下文变量以将 foo.swf 引用正确指向您刚刚编译的内容
哇。 :-P