弹性 4 + Django:测试和发布选项

发布于 2024-09-15 08:14:25 字数 938 浏览 4 评论 0原文

我正在创建一个基于 django 的网站,该网站将为偶尔通过 pyamf 访问数据的 Flash 应用程序提供服务。我需要能够在 django 框架的上下文中轻松测试 flash,即使用所有登录 cookie 和所有可用的内容,以便当我进行 pyamf 调用时,它具有所有用户上下文。我需要能够以合理的方式测试并释放 swf 和包装 html。但是:

  1. flex 中的 html 模板已经是模板,因此如果我将 django 的模板代码放入其中,它会在创建 flashapp.html 之前被删除。
  2. html 和 swf 自动发布到同一目录,但我希望它们转到不同的目录,因为 swf 不应该由 django 提供服务,而 html 应该位于 django 控制的区域中。

乍一看,这让我相信我需要:

  1. 一种将 html 和 swf 文件发布到不同位置的方法。 (我不知道如何做到这一点。)
  2. 一种将 html 作为存根(没有 html/body 标记)发布的方法,以便我可以从 django 中的另一个位置包含它们。 (我想只是从index.template.html中删除我不想要的内容?)
  3. 然后我可以将flex指向django站点,该站点又包含生成的flashapp.html,而flashapp.html又引用了swf,并且它应该所有工作。 (我认为,通过将备用 html 提供给运行/调试设置。)

所以我的问题归结为:

  1. 上面是执行此操作的最佳方法,还是这甚至是正确的方向?
  2. 如果是这样,如何将html和swf发布到不同的目录? (对于debug和release模式,是否有两种不同的方法。)
  3. 如果不是,怎样才是正确的?

如果我对这个主题有任何其他一般性建议,请随时分享。 :-)

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:

  1. The html templates in flex are already templates, so if I put template code in there for django, it gets scraped out before the flashapp.html is created.
  2. The html's and swf's automatically get released to the same directory, but I want them to go to different directories because the swf's shouldn't be served by django and the html's should be in an area in control of django.

This leads me to believe, at first glance, that I need:

  1. A way of having the html and swf files be released to different locations. (I don't know how to do this.)
  2. A way of releasing the html's as stubs (no html/body tag) so that I can include them from another location in django. (I guess just strip what I don't want from the index.template.html?)
  3. Then I can point flex to go to the django site that in turn includes the generated flashapp.html that in turn references the swf, and it should all work. (By feeding that alternate html to the run/debug settings, I assume.)

So my question comes down to:

  1. Is the above the best way of doing this, or is this even the right direction?
  2. If so, how do I release the html and swf to different directories? (For debug and release mode, if there are two different methods.)
  3. If not, what is proper?

And if there are any other general bits of advice for me on this topic, please feel free to share. :-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毁梦 2024-09-22 08:14:25

终于我自己弄清楚了这一点。 的组合这django get-parameters 有效。一般要点:

  1. 您可以放心地将 {% Tags %}{{ Variables }} 放入 index.template.html 中,因为无法自定义当前存在的宏,例如 ${title}
  2. 如果您制作 foo.template.htmlfoo-debug.template .html 位于项目的 html-template 目录中,那么前者将覆盖 index.template.html 进行发布版本,后者用于调试版本(请注意,结果将是 foo-debug.html 而不是 foo.html。)
  3. 您可以将 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:

  1. &debug=true 添加到 url
  2. 将浏览器打开到 /url-to-djangoflash/djangoflash/?name=foo&debug=true
  3. 它在 urls.py 中选择 djangoflash/
  4. 它将请求传递给 djangoflashview{'name':'foo','debug':'true'}views.py< 中的 request.GET /code>
  5. 找出 foo-debug.html 位置的名称和位置,将其传递给 flash_template 上下文变量
  6. ,并将 swf 的 url 传递给 >bin_debug_url 上下文变量
  7. 并加载直接模板 djangoflash.html
  8. ,其中在 djangoflash.html 中包含 foo-debug.html 使用 flash_template 上下文变量对 flash 进行包装
  9. ,然后填充 bin_debug_url 上下文变量,将 foo.swf 引用正确指向您刚刚编译的东西

唷。 :-P

Finally figured this out myself. A combination of this and django get-parameters works. The general take-away:

  1. You can put {% tags %} and {{ variables }} in index.template.html without worry, as there is no way to customize the currently-existing macros there like ${title}
  2. If you make a foo.template.html and foo-debug.template.html in the html-template directory of your project, then the former will override index.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.)
  3. 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

<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's run-debug target:

/url-to-django/djangoflash/?name=foo

When you debug foo.mxml, flex:

  1. Adds &debug=true to the url
  2. Brings up a browser to /url-to-djangoflash/djangoflash/?name=foo&debug=true
  3. Which picks djangoflash/ in urls.py
  4. Which passes the request to djangoflashview and {'name':'foo','debug':'true'} to request.GET in views.py
  5. Which figures out the name and location of the foo-debug.html location, passing it to the flash_template context variable
  6. And the url of the swf to the bin_debug_url context variable
  7. And loads up the direct template djangoflash.html
  8. Which, in djangoflash.html, includes the foo-debug.html wrapper for flash using the flash_template context variable
  9. Which, in turn fills in the bin_debug_url context variable to point the foo.swf reference correctly to the thing you just compiled

Whew. :-P

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文