Flex 4 + Django:测试和发布选项 [英] Flex 4 + Django: Testing and Release Options
问题描述
我正在创建一个基于django的站点,它将为通过 pyamf 偶尔访问数据的Flash应用程序提供服务。我需要能够在django框架的上下文中轻松测试Flash,即所有的登录cookie和一切都可用,所以当我进行一个pyamf调用时,它具有所有的用户上下文。而且我需要测试和,以一种合理的方式发布swf和wrapper html。但是:
I am creating a django-based site that will serve flash apps that occasionally access data via pyamf. I need to be able to easily test the flash in the context of the django framework, i.e. with all the login cookies and everything available, so that when I make a pyamf call, it has all the user context there. And I need to be able to test and release both the swf's and the wrapper html's in a sane way. However:
- flex中的html模板已经是模板,所以如果我将模板代码放在django中,那么在flashapp.html被创建。
- html和swf自动发布到同一个目录,但我希望他们去不同的目录,因为swf不应该由django提供, html应该在一个控制django的区域。
这让我相信,乍一看,我需要: p>
This leads me to believe, at first glance, that I need:
- 将html和swf文件释放到不同位置的方法。 (我不知道该怎么做)。
- 将html作为存根(no html / body标签)发布的方式,以便我们可以将它们从django中的另一个位置包含起来。 (我想只是从index.template.html剥离我不想要的东西?)
- 然后我可以指向flex到django网站,反过来包含生成的flashapp。 html反过来引用swf,它应该都可以工作。 (通过将交替的html提供给运行/调试设置,我假设。)
所以我的问题归结为:
- 上述是最好的做法,还是这个方向呢?
- 如果是,如何将html和swf发布到不同的目录? (对于调试和释放模式,如果有两种不同的方法。)
- 如果没有,什么是正确的?
如果有关于这个话题的任何其他一般建议,请随时分享。 : - )
And if there are any other general bits of advice for me on this topic, please feel free to share. :-)
推荐答案
的组合这个和 django get-parameters 的作品。一般外包:
Finally figured this out myself. A combination of this and django get-parameters works. The general take-away:
- 您可以将
{%tags%}
{{variable}}
在index.template.html
中,不用担心,因为没有办法自定义当前 - 现在的宏就像$ {title}
- 如果你做一个
foo.template.html
和foo-debug.template.html
在项目的html-template
目录中,然后前者将覆盖版本构建的index.template.html
,后者用于调试版本(注意,结果将是foo-debug.html而不是foo.html。 ) - 您可以将参数中的SWF名称传递给django,并将其填入您的目录
- You can put
{% tags %}
and{{ variables }}
inindex.template.html
without worry, as there is no way to customize the currently-existing macros there like${title}
- If you make a
foo.template.html
andfoo-debug.template.html
in thehtml-template
directory of your project, then the former will overrideindex.template.html
for release builds, and the latter for debug builds (note that the result will be foo-debug.html instead of foo.html though.) - You can pass the name of the SWF in a parameter to django, and have it fill in the directory for you
foo-debug.template.html
foo-debug.template.html
<object ...
<param name="movie" value="{{ bin_debug_url }}/${swf}.swf" ...
djangoflash.html
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的运行调试目标:
foo.mxml's run-debug target:
/url-to-django/djangoflash/?name=foo
当您调试foo.mxml时,flex:
When you debug foo.mxml, flex:
- 添加
& debug = true
到url - 将浏览器置于
/ url-to-djangoflash / djangoflash /?name = foo& debug = true
- 在
urls.py
djangoflash / > - 将请求传递给
djangoflashview
和{'name':'foo','debug'在
views.py
中到 - 其中指出了
foo-debug.html
位置的名称和位置,将其传递给flash_template
上下文变量 - 将swf的url转换为
bin_debug_url
上下文变量 - 加载直接模板
djangoflash.html
- 在
djangoflash.html
包括fla的foo-debug.html
包装器sh使用flash_template
上下文变量 - 其中,依次填写
bin_debug_url
上下文变量将foo.swf引用正确地指向刚刚编译的东西
request.GET
- Adds
&debug=true
to the url - Brings up a browser to
/url-to-djangoflash/djangoflash/?name=foo&debug=true
- Which picks
djangoflash/
inurls.py
- Which passes the request to
djangoflashview
and{'name':'foo','debug':'true'}
torequest.GET
inviews.py
- Which figures out the name and location of the
foo-debug.html
location, passing it to theflash_template
context variable - And the url of the swf to the
bin_debug_url
context variable - And loads up the direct template
djangoflash.html
- Which, in
djangoflash.html
, includes thefoo-debug.html
wrapper for flash using theflash_template
context variable - Which, in turn fills in the
bin_debug_url
context variable to point the foo.swf reference correctly to the thing you just compiled
:-P
这篇关于Flex 4 + Django:测试和发布选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!