I'm new to Dojo and Django. That said, I'm trying to write a single-page app and I do not understand how to leverage Django's built-in authentication tools since they are designed around the traditional Django page-per view model.
我是Dojo和Django的新手。也就是说,我正在尝试编写一个单页应用程序,我不明白如何利用Django的内置身份验证工具,因为它们是围绕传统的Django页面视图模型设计的。
I'd like to have all forms, both specific to my app and for auth and django-registration displayed in the <div dojoType="dijit.layout.contentPane" id="mainPane"></div>
. I have mastered getting views rendered as Dojango's @json_response
to display; however, I do not know how to "wrap" existing views so that they do not expect page loads.
我想拥有所有表格,特别是我的应用程序以及在
Is there any conventional strategy for single-page Django apps? I like Django's ORM and Dojo's UI, but they seem to be difficult to fully integrate. Thanks.
单页Django应用程序是否有任何传统策略?我喜欢Django的ORM和Dojo的UI,但它们似乎很难完全集成。谢谢。
##############################################################
# # # #
# LOGOUT # # DISP #
# ########################################## #
# REGSTR # # DISP #
# # MAINPANE # #
# DO_IT # # DISP #
# # Forms, views, etc. # #
# CNTRL # using dojo.xhrGET, xhrPUT # DISP #
# # # #
# QUIT # # DISP #
# # # #
# ########################################## DISP #
# # # #
# # STATUS: MESSAGE # #
# # # #
##############################################################
Edit: Just to be more explicit, I want a flow like this:
编辑:为了更明确,我想要一个这样的流程:
- User clicks "DO_IT" button.
- Dojo xhrGETs the DO_IT form and replaces MAINPANE's content with it.
- User does something with DO_IT form and dojo xhrPOSTs the user's action.
- Dojo replaces the content of MAINPANE with the response.
- Profit
用户单击“DO_IT”按钮。
Dojo xhr获取DO_IT表单并用它替换MAINPANE的内容。
用户使用DO_IT表单和dojo xhrPOSTs执行用户的操作。
Dojo用响应替换MAINPANE的内容。
What is the best/conventional/common/most-documented way of accomplishing this. I know that there are likely many possible approaches. I'm looking for something that is less easy to f@#$-up as a novice.
什么是实现这一目标的最佳/传统/常见/最有记录的方式。我知道可能有很多可能的方法。我正在寻找一些不太容易被f @#$ - 起来作为新手的东西。
1 个解决方案
#1
1
You've pretty much spelt it out. The django view can just return the chunk of HTML that you want in the #MAINPANE div, and you insert it by setting the MAINPANE node's .innerHTML property.
你已经把它拼写出来了。 django视图只能在#MAINPANE div中返回你想要的HTML块,然后通过设置MAINPANE节点的.innerHTML属性来插入它。
Once the user has logged in all the authentication should happen automagically even to Ajax calls, so you don't have to worry about that. But you do have to consider what happens if the authentication fails - you could end up just dumping a 403 Permission Denied message into your #MAINPANE div.
一旦用户登录,所有身份验证都应该自动发生,甚至是Ajax调用,因此您不必担心这一点。但是你必须考虑如果身份验证失败会发生什么 - 你最终可能只是将403 Permission Denied消息转储到#MAINPANE div中。
There's a few other subtleties to this kind of web page design - mostly it becomes impossible to bookmark pages unless you provide a 'permalink' link somewhere that gets you to the page with the required content loaded into the MAINPANE div. And hitting reload in the browser causes surprise when it doesn't reload the current view of the page but jumps back to the 'home' view.
这种网页设计还有一些其他的细微之处 - 除非你在某个地方提供一个'永久链接'链接,然后将你带到加载到MAINPANE div中的所需内容的页面,否则它几乎不可能为页面添加书签。并且当它不重新加载页面的当前视图但跳回到“主页”视图时,在浏览器中重新加载会导致意外。
Or you could just do it the old skool way with FRAME tags :)
或者你可以用FRAME标签做旧的skool方式:)
#1
1
You've pretty much spelt it out. The django view can just return the chunk of HTML that you want in the #MAINPANE div, and you insert it by setting the MAINPANE node's .innerHTML property.
你已经把它拼写出来了。 django视图只能在#MAINPANE div中返回你想要的HTML块,然后通过设置MAINPANE节点的.innerHTML属性来插入它。
Once the user has logged in all the authentication should happen automagically even to Ajax calls, so you don't have to worry about that. But you do have to consider what happens if the authentication fails - you could end up just dumping a 403 Permission Denied message into your #MAINPANE div.
一旦用户登录,所有身份验证都应该自动发生,甚至是Ajax调用,因此您不必担心这一点。但是你必须考虑如果身份验证失败会发生什么 - 你最终可能只是将403 Permission Denied消息转储到#MAINPANE div中。
There's a few other subtleties to this kind of web page design - mostly it becomes impossible to bookmark pages unless you provide a 'permalink' link somewhere that gets you to the page with the required content loaded into the MAINPANE div. And hitting reload in the browser causes surprise when it doesn't reload the current view of the page but jumps back to the 'home' view.
这种网页设计还有一些其他的细微之处 - 除非你在某个地方提供一个'永久链接'链接,然后将你带到加载到MAINPANE div中的所需内容的页面,否则它几乎不可能为页面添加书签。并且当它不重新加载页面的当前视图但跳回到“主页”视图时,在浏览器中重新加载会导致意外。
Or you could just do it the old skool way with FRAME tags :)
或者你可以用FRAME标签做旧的skool方式:)