Pyjamas 和 Django 静态文件设置
我对 Web 开发以及 Django 和 Pyjamas 框架都有点陌生。因此,我很感谢在我学习时给予我的耐心。
我正在设置 Django 和 Pyjamas 一起工作,JSONRPC 客户端/服务器 + Django 模板。
我将编译后的 Pyjamas my_project.html 作为 Django 模板。我将 Django 模板文件夹设置为我的 Pyjamas 项目输出文件夹。
Pyjamas 将 bootstrap.js
编译到同一输出文件夹,我需要在 Django 模板中对这些文件进行正确引用,作为以下文件的当前引用:
<script language="javascript" src="bootstrap.js"></script>
无法正常工作。
即使在阅读了 Django 的文档之后,管理静态文件的方式对我来说也不是很明显。就文件夹层次结构和 Django 设置而言,最好的设置方法是什么?
从 Django 模板中引用静态文件的最佳方式是什么?
我知道我可能会问明显的问题,但在阅读了可用的文档后,我似乎无法将它们放在一起。这是我真正开始滚动之前的最后一块拼图,所以任何帮助将不胜感激!
I am somewhat new to both web development and new to the Django and Pyjamas frameworks. So I appreciate any patience offered to me as I learn.
I am setting up Django and Pyjamas to work together, JSONRPC Client/Server + Django templates.
I have the compiled Pyjamas my_project.html being served as Django templates. I have the Django template folder set to my Pyjamas project output folder.
Pyjamas compiles a bootstrap.js
to the same output folder and I need proper referencing within the Django templates to these files as the current reference of:
<script language="javascript" src="bootstrap.js"></script>
Is not functioning.
The Django way of managing static files is not very obvious to me even after reading it's documentation. What is the best way to set this up in terms of folder hierarchy and Django settings?
What is the best way to reference my static files from within my Django templates?
I know I am likely asking obvious questions but after reading the available documentation I just can't seem to put this together. This is the last piece of the puzzle before I really start rolling so any help will be appreciated greatly!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它不允许我发表评论,但我遇到了同样的问题。回答 Daniel Kluev,我们通过 django 提供 pajamas 页面的原因是因为来自 pajamas 的 JSONRPC 请求 -> django 遇到 django 中的 CSRF 保护,导致 403 错误。我们见过的最好的解决方案(也许是唯一的?)是将令牌作为 cookie(或表单元素)传递给 pajamas,然后可以在 RPC 期间发送回 django。由于 Shattered1113 在他的问题中提到的问题,我们无法实现这一点。
我见过的唯一其他选项是关闭 CSRF 中间件,或使用装饰器从其中免除特定视图。这似乎是每个人都使用的解决方案,但是我们需要启用 csrf 保护,因此它对我们不起作用。
It won't let me comment but I am running into the same issue. To answer Daniel Kluev, our reason for serving the pyjamas page through django is because JSONRPC requests from pyjamas -> django run into the CSRF protections in django, resulting in a 403 error. The best solution (and maybe only?) that we have seen is to pass the token to pyjamas as a cookie (or form element), which can then be sent back to django during the RPCs. We have not been able to implement this due to the issues Shattered1113 mentioned in his question.
The only other option I've seen is to turn off the CSRF middleware, or exempt specific views from it using a decorator. This seems to be the solution everyone uses, however we require the csrf protection to be enabled so it will not work for us.