Home > Blockchain >  Error the current path match any of these
Error the current path match any of these

Time:06-23

updated code: i added '/' end of every route, then the template is loading but it didnt redirecting to the next pageError 404Whenever i try to load login,register page its showing Using the URLconf defined in loan.urls, Django tried these URL patterns, in this order: admin/ [name='index'] login [name='login'] register [name='register'] logout [name='logout'] form [name='form'] predict [name='predict'] The current path, register/, didn’t match any of these How can i solve this issue

from django.urls import path
from . import views
urlpatterns = [
    path('', views.index, name="index"),
    path('login', views.login, name="login"),
    path('register', views.register, name="register"),
    path('logout', views.logout, name="logout"),
    path('form', views.form, name="form"),
    path('predict', views.predict, name="predict"),
]
from django.shortcuts import render, redirect
from django.contrib import messages
from django.contrib.auth.models import User, auth
from .models import Prediction
import joblib
import pandas as pd
from sklearn.preprocessing import scale
from sklearn.impute import SimpleImputer

res = 'X'


# Create your views here.
def index(request):
    return render(request, "index.html")


def login(request):
    if request.method == "POST":
         name = request.POST['username']
         pas = request.POST['password']
         user = auth.authenticate(username=name, password=pas)

    if user:
        auth.login(request, user)
        print(user.is_authenticated)
        return redirect("/")
    else:
        messages.info(request, "User does not exist")
        return redirect("login")
else:
    return render(request, "login.html")


 def register(request):
    if request.method == "POST":
         fname = request.POST['first_name']
         lname = request.POST['last_name']
         email = request.POST['email']
         uname = request.POST['username']
         pas1 = request.POST['password1']
         pas2 = request.POST['password2']
   if pas1 == pas2:
        if User.objects.filter(username=uname).exists():
            messages.info(request, "Username already exists")
            return render(request, "register.html")
        elif User.objects.filter(email=email).exists():
            messages.info(request, "Email already exits")
            return render(request, "register.html")
        else:
            user = User.objects.create_user(username=uname, password=pas1, email=email, first_name=fname,
                                            last_name=lname)
            user.save()
            print('User Created')
            return redirect("login")
    else:
        messages.info(request, "Password does not match")
        return render(request, "register.html")
else:
    return render(request, "register.html")

loan.urls

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('user.urls')),
]

user.urls

from django.urls import path
from . import views

path('', views.index, name="index"),
path('login', views.login, name="login"),
path('register', views.register, name="register"),
path('logout', views.logout, name="logout"),
path('form', views.form, name="form"),
path('predict', views.predict, name="predict"),

register.html

{% load static %}
<!DOCTYPE html>
<html>
<head>
<title>Register</title>
<meta name="viewport" content="width=device-width, initial- 
scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" 
/>
<link rel="icon" href="{% static 'index/images/logo.png' %}">
<script type="application/x-javascript"> addEventListener("load", 
function() { setTimeout(hideURLbar, 0); }, false); function 
hideURLbar(){ window.scrollTo(0,1); } </script>
<!-- Custom Theme files -->
<link href="{% static 'user/css/styler.css' %}" rel="stylesheet" 
type="text/css" media="all" />
<!-- //Custom Theme files -->
<!-- web font -->
<link href="//fonts.googleapis.com/css? 
family=Roboto:300,300i,400,400i,700,700i" rel="stylesheet">
<!-- //web font -->
</head>
<body>
<!-- main -->
<div >
    <h1>Register</h1>
    <div >
        <div >
            {% for message in messages %}
            <h6 style="color:red">{{message}}</h6><br>
            {% endfor %}
            <form action="register" method="post">
                {% csrf_token %}
                <input  type="text" name="first_name" 
placeholder="First Name" required="">
                <input  type="text" name="last_name" 
placeholder="Last Name" required=""><br>
                <input  type="text" name="username" 
placeholder="Username" required="">
                <input  type="email" name="email" 
placeholder="Email" required="">
                <input  type="password" 
name="password1" placeholder="Password" required="">
                <input  type="password" 
name="password2" placeholder="Confirm Password" required="">
                <div >
                    <label >
                        <input type="checkbox"  
required="">
                        <span>I Agree To The Terms & 
Conditions</span>
                    </label>
                    <div > </div>
                </div>
                <input type="submit" value="SIGNUP">
            </form>
            <p>Already have an Account? <a href="login"> Login</a> 
</p>
        </div>
    </div>
    <!-- copyright -->
    <div >
        <p>© 2018 Colorlib Signup Form. All rights reserved | 
Design by <a href="https://colorlib.com/" 
target="_blank">Colorlib</a></p>
    </div>
    <!-- //copyright -->
    <ul >
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
    </ul>
</div>
<!-- //main -->
</body>
</html>

CodePudding user response:

You are missing / in your paths. Try to always add it to the end of path:

path('', views.index, name="index"),
path('login/', views.login, name="login"),
path('register/', views.register, name="register"),
path('logout/', views.logout, name="logout"),
path('form/', views.form, name="form"),
path('predict/', views.predict, name="predict"),

Another thing is you don't need action="register" which might interfere classic Django behaviour.

  • Related