page not found but url exists

31 views
Skip to first unread message

Kean

unread,
Aug 26, 2019, 1:10:09 PM8/26/19
to Django users
Hi, 

I'm new to Django. I created several urls, in urls.py, however, when I try to navigate to the URL it says page not found.

Page not found (404)

Request Method:GET
Request URL:http://127.0.0.1:8000/register

Using the URLconf defined in bnt.urls, Django tried these URL patterns, in this order:

  1. admin/
  2. [name='home']
  3. /login [name='clogin']
  4. /login/customer [name='cpage']
  5. /register [name='cregister']
  6. /register/customer [name='cpage']

The current path, register, didn't match any of these.






urls.py

from django.conf.urls import url
from django.urls import path
from . import views

urlpatterns = [

    path('', views.home, name='home'),
    path('/login', views.clogin, name='clogin'),
    path('/login/customer', views.cpage, name='cpage'),
    path('/register', views.cregister, name='cregister'),
    path('/register/customer', views.cpage, name='cpage'),
    path('/logout', views.clogout, name='clogout'),
    
]


Please can anyone advise, if they had this issue and how they resolved,

Best,

K

Gil Obradors

unread,
Aug 26, 2019, 1:30:15 PM8/26/19
to django...@googlegroups.com
Hi!

Can you paste views.cregister
and projectname/urls.py ?



Missatge de Kean <kea...@gmail.com> del dia dl., 26 d’ag. 2019 a les 19:10:
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8a72d003-fcf7-4280-8635-6f4986f3e002%40googlegroups.com.

Kean

unread,
Aug 26, 2019, 1:32:51 PM8/26/19
to django...@googlegroups.com
Hi Gil,

please see

views.cregister

def cregister(request):
    next = request.GET.get('next')
    form = CUserRegisterForm(request.POST or None)
    if form.is_valid():
        user = form.save(commit=False)
        password1 = form.cleaned_data.get('password1')
        password1 = form.cleaned_data.get('password2')
        user.setpassword(password1)
        user.setpassword(password2)
        user.save()
        new_user = authenticate(username=username, password=password)
        login(request, user)
        if next:
            return redirect('next')
        return redirect('cpage')

    context = {

        'form': form,

    }
    return render(request, "cregister.html", context)

projectname/urls.py

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

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

Best,

K

Gil Obradors

unread,
Aug 26, 2019, 3:18:11 PM8/26/19
to django...@googlegroups.com
admin/ urls are working fine?
if you put print('hello0) at first line inside cregister, you see at the console?

If yes the problem is in redirects


Missatge de Kean <kea...@gmail.com> del dia dl., 26 d’ag. 2019 a les 19:32:

Kean Dumba

unread,
Aug 26, 2019, 3:50:42 PM8/26/19
to django...@googlegroups.com
Tried this with print request,
However it didn’t improve the issue.

It can’t be a redirect issue, as it’s not even finding the first instance of the url which is GET action. The redirect is only actionable after on page actions I.e. user register Name, email etc.

Are their any other root causes to this.

Best,

K



Luca Mazzilli

unread,
Aug 26, 2019, 5:04:06 PM8/26/19
to Django users
Kean,
Have you tried removing the initial slash inside the path?

James Schneider

unread,
Aug 26, 2019, 5:46:18 PM8/26/19
to django...@googlegroups.com



Using the URLconf defined in bnt.urls, Django tried these URL patterns, in this order:

  1. admin/
  2. [name='home']
  3. /login [name='clogin']
  4. /login/customer [name='cpage']
  5. /register [name='cregister']
  6. /register/customer [name='cpage']

The current path, register, didn't match any of these.



I'm assuming your template has a typo in the {% url %} tag referencing 'register' instead of 'cregister'. 

The rest of the error page should indicate the line that is making the URL name resolution call.

-James

Sipum

unread,
Aug 26, 2019, 6:12:56 PM8/26/19
to django...@googlegroups.com
Hey,

Try by giving forward slashes(/) at the end of the each urls instead of using backward slashes like...

Do as - 
register/
login/customer/

I think It will work.... 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Frederick Johnson

unread,
Aug 27, 2019, 10:47:14 AM8/27/19
to Django users
I think you should remove the / at the begining

Kean

unread,
Aug 27, 2019, 11:00:57 AM8/27/19
to django...@googlegroups.com
Hi Luca,

your suggestion worked, thank you.
many thanks to the community for the ongoing advice and help, it really makes a huge and valuable difference.

Best,

K
On 26 Aug 2019, at 20:59, Luca Mazzilli <luca.m...@gmail.com> wrote:

> Kean,
> Have you tried removing the initial slash inside the path?
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bc263648-0291-44af-96c6-a7f1b2f5141f%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages