Skip to content
Advertisement

Page not found (404) The current path, register/register, didn’t match any of these

on running server browser show

I am trying to save the the data into database on submitting the form the browser show page not found error and and some wrong address. http://127.0.0.1:8000/register/register while i am rendering the homepage on submitting the form.

views.py file

from django.http import HttpResponse
from django.shortcuts import render, redirect
from django.contrib.auth.models import User

def homePage(request):
    return render(request,"index.html")

def register(request):
    if request.method=='POST':
         firstname = request.POST.get('fname')
         lastname = request.POST.get('lname')
         email = request.POST.get('email')
         password = request.POST.get('password')
         username = request.POST.get('uname')
         user = User(first_name=firstname,last_name=lastname,email=email,password=password,username=username)
         user.save()
    return redirect('/')

    return render(request,"register.html")

def course(request):
    return HttpResponse("welcome to my 2nd page")

def courseDetail(request,courseid):
    return HttpResponse(courseid)

urls.py file

from django.urls import include, path
from django.contrib import admin
from django.urls import path
from name import views
import name
urlpatterns = [
 path('admin/', admin.site.urls),
 path('',views.homePage),
 path('register/',views.register),
 path('course/',views.course),
 path('course/<courseid>',views.courseDetail),
]

Advertisement

Answer

try path(‘register/register’,views.register),

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement