4

I have just today started working with django.

I tried executing the run server command but I keep encountering the Page not found error.

I have been trying to debug the problem for almost an hour now.

Project rms > myrms (app)

Edit:

I have initally doubly defined url patterns statement which was pointed out by meshy. I corrected that error but still the code is not working. Help.

myrms/view.py

from django.http import HttpResponse
# Create your views here.
def index(request):
    return HttpResponse("Hello,World. You're at the polls index.")

myrms/urls.py

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

urlpatterns = [
    path('', views.index,name = 'index'),
    path('myrms/', include('myrms.urls')),
    path('admin/', admin.site.urls),
]

It's expected to show the hello world statement but keeps on turning up Page not found error on running manage.py runserver Performing system checks...

System check identified no issues (0 silenced).
February 18, 2019 - 18:41:24
Django version 2.1.7, using settings 'RMS.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[18/Feb/2019 18:41:36] "GET /myrms/ HTTP/1.1" 404 77

I am trying to open. url"http://localhost:8000/myrms/" or "http://127.0.0.1:8000/myrms/" both are showing error

9
  • to serve index change url pattern '' to '^$' Feb 18, 2019 at 12:51
  • Hi. Can you please elaborate how that helps> Feb 18, 2019 at 12:57
  • Please add some information: a) what do you get after python manage.py runserver, b) which url you are trying to open, c) stack trace of error - copy-paste text from "Page not found error", d) look at your command line - what manage.py runserver printing?
    – Alex Yu
    Feb 18, 2019 at 13:03
  • You've modified your question, and my answer is now obsolete.
    – meshy
    Feb 18, 2019 at 13:10
  • @meshy you helped to remove another error. It must be of help for OP in any case
    – Alex Yu
    Feb 18, 2019 at 13:12

1 Answer 1

3

You're including this file, from this file recursively.

Remove this line, it's redundant because you're writing it from within myrms/urls.py:

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

Change the URL of your view to match the URL you're accessing:

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

Alternatively, access a different URL: http://localhost:8000/

Ensure that ROOT_URLCONF is set to myrms.urls.

Another old answer

You are using '^$', but that is for re_path(), not path().

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

Original answer, before question changed

You've defined urlpatterns twice. The second time you define it, you override the first.

To correct this, combine the two lists:

urlpatterns = [
    path('', views.index,name = 'index'),
    path('myrms/', include('myrms.urls')),
    path('admin/', admin.site.urls),
]
2
  • I corrected the url file and I also used that '' to '^$' change still it shows page not found error Feb 18, 2019 at 13:03
  • Please tell me a suitable tutorial available online that can help me learn django Feb 18, 2019 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.