单击提交按钮时出现TypeError错误

时间:2015-06-27 18:49:57

标签: html django twitter-bootstrap login

我在django webapp中使用bootstrap。我有以下base.html

<!DOCTYPE html>
<html lang="en">

<head>
    {% load static %}
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Kevin's Blog</title>

    <!-- Bootstrap Core CSS -->
    <link href="{% static 'blog/css/bootstrap.min.css' %}" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="{% static 'blog/css/clean-blog.min.css' %}" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href='http://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body>

    <!-- Navigation -->
    <nav class="navbar navbar-default navbar-custom navbar-fixed-top">
        <div class="container-fluid">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header page-scroll">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>

                {% if user.is_active %}
                    <span class="navbar-brand" href="{% url 'login' %}" style="font-size: 15px">{{user.username}}</span>
                    <a class="navbar-brand" href="/logout/" style="font-size: 15px">log out</a>
                {% else %}
                    <a class="navbar-brand" href="{% url 'login' %}" style="font-size: 15px">Login</a>
                    <a class="navbar-brand" href="{% url 'register' %}" style="font-size: 15px">Signup</a>
                {% endif %}


            </div>

            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <a href="{% url 'index' %}">Home</a>
                    </li>
                    <li>
                        <a href="{% url 'about' %}">About</a>
                    </li>
                    <li>
                        <a href="{% url 'post' %}">Post</a>
                    </li>
                    <li>
                        <a href="{% url 'project' %}">Project</a>
                    </li>
                    <li>
                        <a href="{% url 'contact' %}">Contact</a>
                    </li>
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container -->
    </nav>

    {% block content %}
    {% endblock content %}

        <!-- Footer -->
    <footer>
        <div class="container">
            <div class="row">
                <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                    <ul class="list-inline text-center">
                        <li>
                            <a href="http://www.linkedin.com/in/wz246">
                                <span class="fa-stack fa-lg">
                                    <i class="fa fa-circle fa-stack-2x"></i>
                                    <i class="fa fa-linkedin fa-stack-1x fa-inverse"></i>
                                </span>
                            </a>
                        </li>
                        <li>
                            <a href="http://www.facebook.com/hitzhuwen">
                                <span class="fa-stack fa-lg">
                                    <i class="fa fa-circle fa-stack-2x"></i>
                                    <i class="fa fa-facebook fa-stack-1x fa-inverse"></i>
                                </span>
                            </a>
                        </li>
                        <li>
                            <a href="http://github.com/spoiledPiggy">
                                <span class="fa-stack fa-lg">
                                    <i class="fa fa-circle fa-stack-2x"></i>
                                    <i class="fa fa-github fa-stack-1x fa-inverse"></i>
                                </span>
                            </a>
                        </li>
                    </ul>
                    <p class="copyright text-muted">Copyright &copy; Kevin's Website 2015</p>
                </div>
            </div>
        </div>
    </footer>

    <!-- jQuery -->
    <script src="{% static 'blog/js/jquery.js' %}"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="{% static 'blog/js/bootstrap.min.js' %}"></script>

    <!-- Custom Theme JavaScript -->
    <script src="{% static 'blog/js/clean-blog.min.js' %}"></script>

</body>

</html>

现在我想创建一个登录页面(扩展base.html

{% extends 'base.html' %}

{% block content %}

<div class="container"> 

<div id="loginbox" style="margin-top:50px;" class="mainbox col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2">                    
    <div class="panel panel-info" >
            <div class="panel-heading">
                <div class="panel-title">Sign In</div>
                <div style="float:right; font-size: 80%; position: relative; top:-10px"><a href="#">Forgot password?</a></div>
            </div>     

            <div style="padding-top:30px" class="panel-body" >

                <div style="display:none" id="login-alert" class="alert alert-danger col-sm-12"></div>

                <form action="/auth/" id="loginform" class="form-horizontal" role="form" method="post">
                {% csrf_token %}

                    <div style="margin-bottom: 25px" class="input-group">
                                <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
                                <input id="username" type="text" class="form-control" name="username" value="" placeholder="username or email">                                        
                    </div>

                    <div style="margin-bottom: 25px" class="input-group">
                                <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
                                <input id="login-password" type="password" class="form-control" name="password" placeholder="password">
                    </div>

                    <div class="input-group">
                        <div class="checkbox">
                            <label>
                                <input id="login-remember" type="checkbox" name="remember" value="1"> Remember me
                            </label>
                        </div>
                    </div>

                        <div style="margin-top:10px" class="form-group">
                            <!-- Button -->
                            <div class="col-sm-12 controls">
                              <input type="submit" id="btn-login" class="btn btn-success" value="login" />
                              <a id="btn-fblogin" href="#" class="btn btn-primary">Login with Facebook</a>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-md-12 control">
                                <div style="border-top: 1px solid#888; padding-top:15px; font-size:85%" >
                                    Don't have an account! 
                                <a href="#" onClick="$('#loginbox').hide(); $('#signupbox').show()">
                                    Sign Up Here
                                </a>
                                </div>
                            </div>
                        </div>    
                    </form>     

                </div>                     
            </div>  
</div>
</div>
{% endblock %}

login提交按钮不起作用,但如果我删除base.html(我将丢失CSS ...),那就没关系了。任何人都可以帮忙吗?

当我点击提交按钮时,控制台出现错误。

  

未捕获的TypeError:无法读取属性&#39; indexOf&#39;的   undefined $ .jqBootstrapValidation.submitSuccess @   clean-blog.min.js:7(匿名函数)@   clean-blog.min.js:7jQuery.event.dispatch @   jquery.js:4409elemData.handle @jquery.js:4095

0 个答案:

没有答案