4

我对这个话题非常陌生,但我正在尝试将 Django 和 Pyjamas 结合起来。将两者结合起来的聪明方法是什么?我问的不是沟通,而是逻辑部分。

我是否应该将所有睡衣生成的 JS 放在域的基础中,比如http://www.mysite.com/something并在子目录甚至子域上设置 Django,所以所有 JSON 调用都将用于http:/ /something.mysite.com/something

据我所知,在这种组合中,在 Django 中创建视图没有多大意义?

是否有一些解决睡衣中干净网址的解决方案,或者应该在其他级别上解决?如何?在调用睡衣生成的 JS 时,在干净的 url 中将一些参数作为 GET 参数传递是一种标准方法吗?

4

3 回答 3

2

你应该看看好的Django With Pajamas Howto。

于 2010-03-22T15:12:01.963 回答
2

我已经设法让以下工作,但这并不理想。完全披露:我还没有弄清楚如何使用 django 的模板系统将内容放入睡衣 UI 元素中,并且我还没有确认此设置适用于 django 的身份验证系统。我唯一确认的是,这会让睡衣生成的页面显示出来。这就是我所做的。

  • 将睡衣生成的主要 .html 文件放在 django 的“模板”目录中,并从您的项目中提供它,就像提供任何其他模板一样。

  • 将所有其他内容放在 django 的“静态”文件目录中。

  • 对 pyjamas 生成的主 .html 文件进行以下更改:在 head 部分找到 name="pygwt:module" 的 meta 元素并将 content="..." 属性更改为 content="/static/.. ." 其中 "/static/" 是您在 django 中配置的静态页面 URL 路径;在正文部分找到带有 src="bootstrap.js" 的脚本元素,并将属性替换为 src="/static/bootstrap.js"。

每次使用睡衣重新生成文件时,您都需要手动进行这些编辑。似乎没有办法告诉睡衣在一起生成其输出时使用特定的 URL 前缀。哦,好吧,睡衣的凉爽弥补了很多。

于 2012-05-01T19:36:51.350 回答
1

acid, I'm not sure this is as much an answer as you would hope but I've been looking for the same answers as you have.

As far as I can see the most practical way to do it is with an Apache server serving Pyjamas output and Django being used as simply a service API for JSONrpc calls and such.

On a side note I am starting to wonder if Django is even the best option for this considering using it simply for this feature is not utilizing most of it's functionality.

The issue so far as I have found with using Django to serve Pyjamas output as Django Views/Templates is that Pyjamas loads as such

Main html page loads "bootstrap.js" and depending on the browser used bootstrap.js will load the appropriate app page. Even if you appropriately setup the static file links using the Django templating language to reference and load "bootstrap.js", I can't seem to do the same for bootstrap.js referencing each individual app page.

This leaves me sad since I do so love the "cruftless URLS" feature of Django.

于 2011-06-13T21:41:31.663 回答