weixin_33719619 2018-03-01 15:31 采纳率: 0%
浏览 28

Django在模式窗口中登录

I would like to create login with django in popup modal window.

For login/registration I use package django-registration-redux, for popup modal window i use jquery form plugin.

In the older version of django-registration-redux everything worked, but now I don't know why it is not working.

My JS code:

function initModalWindowPage() {
    $('a.modal-form-link').click(function(event) {
        var link = $(this);
        $.ajax({
            'url': link.attr('href'),
            'dataType': 'html',
            'type': 'get',
            'success': function(data, status, xhr) {
                if (status != 'success') {
                    return false;
                }
                var modal = $('#myModal'),
                    html = $(data),
                    form = html.find('#content-column form');
                modal.find('.modal-title').html(html.find('#content-column h2').text());
                modal.find('.modal-body').html(form);
                initModalWindowForm(form, modal);
                modal.modal({
                    'keyboard': false,
                    'backdrop': false,
                    'show': true
                });
            },
        });

        return false;
    });
}

function initModalWindowForm(form, modal) {
    form.ajaxForm({
        'dataType': 'html',
        'error': function() {
            return false;
        },
        'success': function(data, status, xhr) {
            var html = $(data),
                newform = html.find('#content-column form');
            modal.find('.modal-body').html(html.find('.alert'));
            if (newform.length > 0) {
                modal.find('.modal-body').append(newform);
                initModalWindowForm(newform, modal);
            } else {
                setTimeout(function() {
                    location.reload(true);
                }, 500);
            }
        }
    });
}


$(document).ready(function() {
    initModalWindowPage();
});

base.html:

<a class="modal-form-link" href="{% url 'login' %}">{% trans "Login" %}</a>

...

<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
    aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <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" id="myModalLabel"</h4>
            </div>
            <div class="modal-body"></div>
            <div class="modal-footer"></div>
        </div>
    </div>
</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 求数据集和代码#有偿答复
    • ¥15 关于下拉菜单选项关联的问题
    • ¥15 如何修改pca中的feature函数
    • ¥20 java-OJ-健康体检
    • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
    • ¥15 使用phpstudy在云服务器上搭建个人网站
    • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
    • ¥15 vue3+express部署到nginx
    • ¥20 搭建pt1000三线制高精度测温电路
    • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况