AJAX 请求后填充 Django 表单
我正在开发一个 django 应用程序,它大致基于 django 书中的书籍示例。我在表格中显示了一个书籍数据库,当您单击该书籍时,它会将您带到“/editbook/bookname”,其中显示一个模型表单。
我想转而在表格上的模式对话框中显示表单 - 这意味着模式对话框代码已经在模板上就位,如下所示(简化!)
<div id="modal">
{{form.as_table}}
</div>
页面加载,然后向“/”发出 AJAX 请求editbook/bookname”,当用户选择一本书时;显然,表单不会显示,因为发出请求时页面已经呈现 - 如何适当更新页面,以便在发出请求后表单实际呈现?
谢谢
I've got a django app in progress that is based loosely on the books example in the django book. There is a database of books which I have displayed in a table, when you click on the book it takes you to "/editbook/bookname" where it displays a ModelForm.
I'd like to move over to displaying the form in a modal dialog over the table - meaning the modal dialog code is already in place on the template like so (simplified!)
<div id="modal">
{{form.as_table}}
</div>
The page loads and then an AJAX request is made to "/editbook/bookname" when the user selects a book; obviously the form won't display as the page is already rendered when the request is made - how can I update the page suitably so the form actually renders once the request has been made?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
大多数模态窗口实现(如 jqModal、jQueryUI、Fancybox 等)允许您将内容加载到 iFrame 中的模态中。
您可以创建一个包含表单的视图,将其加载到模式中的 iFrame 中,然后从那里开始。这是我在多个 Django 项目中多次使用的模式。
Most modal window implementations like jqModal, jQueryUI, Fancybox, etc, allow you to load content into the modal in an iFrame.
You could just create a view that contains your form that you load into the iFrame in the modal and go from there. It's a pattern I've used many times on several Django projects.