django encountered with ConnectionResetError: [WinError 10054]

254 views Asked by At

I am new to django and would like to write a simple log in web page frontend: html, css, javascript(using bootstrap and jquery) After filling the username and password and clicking the sign in button, it is supposed to jump to the home page. Here is my code: html:

 <form id="sign-form" role="form">
     {% csrf_token %}

     <div class="form-group">
         <label for="name" class="sr-only"> username </label>
         <input id="name" type="text" class="form-control" placeholder="Username...">
     </div>

     <div class="form-group">
         <label for="password" class="sr-only"> password </label>
         <input id="password" type="password" class="form-control" placeholder="Password...">
     </div>

     <div class="form-group">
         <button class="btn btn-block" id="sign-in-button"> Sign in </button>
     </div>

     <div class="form-group">
         <button class="btn btn-block" id="sign-up-button"> Sign up </button>
     </div>

</form>

js:

$("#sign-in-button").click(function () {
    var name=$("#name").val();
    var word=$("#password").val();

    $.post("/login/",
        {
            'username': name,
            'password': word
        },
        function (result) {
            alert(result);
        }
        );

});

urls:

urlpatterns = [
    path('admin/', admin.site.urls),
    path(r'landing/', views.landing_page),
    path(r'login/', views.login),
    path(r'homepage/', views.home_page),
]

views:

def landing_page(request):
    return render(request, "landingPage.html")


def login(request):
    print("here log in")
    if request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = auth.authenticate(username=username, password=password)
        print(username+" out")
        if user is not None:
            auth.login(request, user)
            print(username)
            return render(request, "homePage.html", {'username': username})
        return render(request, "homePage.html")

    return render(request, "homePage.html")

But I encountered this problem(please have a look at the pictures): The remote host forced the closure of an existing connection

The remote host forced the closure of an existing connection

The remote host forced the closure of an existing connection

0

There are 0 answers