Error in Django url mapping

783 views
Skip to first unread message

The Aryas

unread,
Mar 23, 2019, 12:08:24 PM3/23/19
to Django users
Hey Guys, I am facing problem on django url mapping, I did exactly what my couse said and copied the code text exactly,but it throws the error:-


Page not found (404)

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

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

  1. admin/
  2. [name='index']

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

You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.




##The code I written in my project are;:-

--------------------------------------------------------------------

<urls.py-first_project>


from django.contrib import admin

from django.urls import path, include


urlpatterns = [

    path('admin/', admin.site.urls),

    path('first_app/', include('first_app.urls'))


]

----------------------------------------------------------------------

-----------------------------------------------------------------------


<urls.py-first_app>


from django.contrib import admin

from django.urls import path

from . import views

urlpatterns = [

    path('index/', views.index, name="index"),

]


-------------------------------------------------------------------------
--------------------------------------------------------------------------
<views.py>

from django.shortcuts import render
from django.http import HttpResponse

# Create your views here.
def index(request):
    return HttpResponse("Hello World")
----------------------------------------------------------------------------
----------------------------------------------------------------------------

<settings.py>

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'first_app'
]

-------------------------------------------------------------------------------

I dont know what to do , I could not find the error plz assist me, I am a begginer to this cousre,
Thank You!!

egbosi Kelechi

unread,
Mar 23, 2019, 12:20:25 PM3/23/19
to django...@googlegroups.com
Great. You are on the right track, only that the Url path you typed in the address bar triggered the error.

You should use /first_app/index/
Reason:the index url path is located in the first_app. Urls file.

--
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 post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4af88190-6f81-409a-aafa-0b6cfda63d70%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

The Aryas

unread,
Mar 23, 2019, 1:11:36 PM3/23/19
to Django users

1553361011564643730190.jpg


I just did the same..see the result

charan

unread,
Mar 23, 2019, 1:27:43 PM3/23/19
to django...@googlegroups.com

Hello,

The code is absolute ,the thing is that u may have edited the code more than once and didn’t save it or some thing happened the url path is checking in protwos.urls it should check in first_app.urls.....so delete the app and create app again with same code Title: see the error messageu will see the result

 

Sent from Mail for Windows 10

 

From: The Aryas
Sent: 23 March 2019 22:42
Subject: Re: Error in Django url mapping

 

1553361011564643730190.jpg


I just did the same..see the result

 


On Saturday, March 23, 2019 at 9:50:25 PM UTC+5:30, egbosi Kelechi wrote:

Great. You are on the right track, only that the Url path you typed in the address bar triggered the error.

 

You should use /first_app/index/

Reason:the index url path is located in the first_app. Urls file.

 

On Sat, Mar 23, 2019, 5:07 PM The Aryas <arya2...@gmail.com wrote:

Hey Guys, I am facing problem on django url mapping, I did exactly what my couse said and copied the code text exactly,but it throws the error:-

 

 

Page not found (404)

Request Method:

GET

Request URL:

http://127.0.0.1:8000/index

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

1. admin/

2. [name='index']

Thaddeaus Iorbee

unread,
Mar 24, 2019, 8:13:48 AM3/24/19
to Django users
In your urls.py first_app, change 'index' to ''. That is empty string.

127.0.0.1:8000/first_app

That's all you need. It should work.

Thaddeaus Iorbee

unread,
Mar 24, 2019, 8:13:49 AM3/24/19
to Django users
Sorry, it should be first_project

omar ahmed

unread,
Mar 24, 2019, 12:05:18 PM3/24/19
to Django users
hello ...
your code is good
but you forgot to put comma after second path in urls.py

urlpatterns = [

    path('admin/', admin.site.urls),

    path('first_app/', include('first_app.urls')),


]

Reply all
Reply to author
Forward
0 new messages