django 视图能显示模态窗体吗?

2016-02-23 08:49:57 +08:00
 zanpen2000

我是不是把前端后端的概念弄混了?弹窗应该属于前端的事情, django 属于服务器端,应该不行的吧?

初学前端,很多问题不解。还请各位耐心指导。

如下代码会跳转到新的 html 页面,但我想要的是弹出一个 modal 窗体, 目前我是在页面中用 js 实现的弹窗

视图

def functions_edit(request, id):
    f = get_object_or_404(Functions,pk=int(id))
    form = FunctionForm(initial={'function_name': f.name, 'function_desc':f.desc, 'level':f.level.id, 'class_name': f.class_name})
    context = {'modal_title':'编辑 111', 'form':form, 'posturl':'/main/functions/'}
    return render_to_response('modal_base.html', context)

modal_base.html

{% load bootstrap3 %}
<div class="modal fade" id="func_edit">
    <div class="modal-dialog">
        <div class="modal-content">
            <form class="form" action="{{ posturl }}" method="post">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">{% block modal_title %}{{modal_title}}{% endblock %}</h4>
                </div>
                <div class="modal-body">
                    {% csrf_token %}
                    {% bootstrap_form form %}
                    <div class="clearfix"></div>
                </div>
                <div class="modal-footer">
                    <button type='submit' class='btn btn-success' >Save</button>
                    <button type='button' class='btn btn-default ' data-dismiss="modal">Close</button>
                </div>
            </form>
        </div>
    </div>
</div>
1700 次点击
所在节点    问与答
1 条回复
virusdefender
2016-02-23 08:59:03 +08:00
和 Django 没关系,这是前端的问题

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/258373

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX