zanpen2000
V2EX  ›  问与答

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

  •  
  •   zanpen2000 · Feb 23, 2016 · 2338 views
    This topic created in 3766 days ago, the information mentioned may be changed or developed.

    我是不是把前端后端的概念弄混了?弹窗应该属于前端的事情, 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>
    
    1 replies    2016-02-23 08:59:03 +08:00
    virusdefender
        1
    virusdefender  
       Feb 23, 2016
    和 Django 没关系,这是前端的问题
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3704 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 55ms · UTC 05:03 · PVG 13:03 · LAX 22:03 · JFK 01:03
    ♥ Do have faith in what you're doing.