关于 Django、Pajamas 和 Clean URL 的一些基本问题
我对这个主题还很陌生,但我正在尝试将 Django 和 Pyjamas 结合起来。将两者结合起来的明智方法是什么?我问的不是沟通,而是逻辑部分。
我是否应该将所有 Pyjamas 生成的 JS 放在域的底部,比如 http://www.mysite.com /something 并在子目录甚至子域上设置 Django,因此所有 JSON 调用都将针对 http ://something.mysite.com/something ?
据我现在了解,在这样的组合中,在 Django 中创建视图没有多大意义?
Pyjamas 中是否有一些干净网址的解决方案,或者应该在其他级别上解决?如何?在调用 Pyjamas 生成的 JS 时,在干净的 url 中将一些参数作为 GET 参数传递是标准方法吗?
I am farily new to the topic, but I am trying to combine both Django and Pyjamas. What would be the smart way to combine the two? I am not asking about communication, but rather about the logical part.
Should I just put all the Pyjamas generated JS in the base of the domain, say http://www.mysite.com/something and setup Django on a subdirectory, or even subdomain, so all the JSON calls will go for http://something.mysite.com/something ?
As far as I understand now in such combination theres not much point to create views in Django?
Is there some solution for clean urls in Pyjamas, or that should be solved on some other level? How? Is it a standard way to pass some arguments as GET parameteres in a clean url while calling a Pyjamas generated JS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你应该看看Django With Pyjamas Howto。
You should take a look at the good Django With Pyjamas Howto.
我已经设法让以下工作发挥作用,但并不理想。全面披露:我还没有弄清楚如何使用 django 的模板系统将内容添加到 pajamas UI 元素中,并且我还没有确认此设置是否适用于 django 的身份验证系统。我唯一确认的是,这会显示睡衣生成的页面。这就是我所做的。
将 pajamas 生成的主 .html 文件放在 django 的“templates”目录中,并像提供任何其他模板一样从项目中提供它。
将其他所有内容放入 django 的“静态”文件目录中。
对 pyjamas 生成的主 .html 文件进行以下更改:在 head 部分中找到 name="pygwt:module" 的 meta 元素,并将 content="..." 属性更改为 content="/static /...”其中“/static/”是你在django中配置的静态页面URL路径;在正文部分中找到带有 src="bootstrap.js" 的 script 元素,并将该属性替换为 src="/static/bootstrap.js"。
每次使用 pyjamas 重新生成文件时,您都需要手动进行这些编辑。似乎没有办法告诉 pajamas 在生成输出时使用特定的 URL 前缀。哦,好吧,睡衣的凉爽弥补了很多。
I've managed to get the following to work, but it's not ideal. Full disclosure: I haven't figured out how to use the django's template system to get stuff into the pyjamas UI elements, and I have not confirmed that this setup works with django's authentication system. The only thing I've confirmed is that this gets the pyjamas-generated page to show up. Here's what I did.
Put the main .html file generated by pyjamas in django's "templates" directory and serve it from your project the way you'd serve any other template.
Put everything else in django's "static" files directory.
Make the following changes to the main .html file generated by pyjamas: in the head section find the meta element with name="pygwt:module" and change the content="..." attribute to content="/static/..." where "/static/" is the static page URL path you've configured in django; in the body section find the script element with src="bootstrap.js" and replace the attribute with src="/static/bootstrap.js".
You need to make these edits manually each time you regenerate the files with pyjamas. There appears to be no way to tell pyjamas to use a specific URL prefix when generating together its output. Oh well, pyjamas' coolness makes up for a lot.
酸,我不确定这是否是您希望的答案,但我一直在寻找与您相同的答案。
据我所知,最实用的方法是使用 Apache 服务器提供 Pyjamas 输出,并将 Django 用作 JSONrpc 调用等的简单服务 API。
顺便说一句,我开始怀疑 Django 是否是最好的选择,考虑到仅仅因为这个特性而使用它并没有利用它的大部分功能。
到目前为止,我发现使用 Django 将 Pyjamas 输出作为 Django 视图/模板提供服务的问题是 Pyjamas 加载,
主 html 页面加载“bootstrap.js”,并且根据使用的浏览器 bootstrap.js 将加载适当的应用程序页面。即使您使用 Django 模板语言正确设置静态文件链接来引用和加载“bootstrap.js”,我似乎也无法对引用每个单独应用程序页面的 bootstrap.js 执行相同的操作。
这让我很伤心,因为我非常喜欢 Django 的“cruftless URLS”功能。
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.