Home > Software engineering >  Django FirstApp
Django FirstApp

Time:02-05

`# This is the url :Link

views.py code:

` from django.http import HttpResponse

def index(request):
return HttpResponse("Hello, world. You're at the poll index.")`

urls.py code: (this is inside polls app urls.py file) :

` from django.urls import path, include from django.conf import settings

 from . import views

 urlpatterns = [
 path(r'^$', views.index, name='index'),
 ]

`

urls.py code : ( this is root urls.py file code):

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

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

`

here my run command : python manage.py runserver 8080

Unable to run this I am getting an error:

`Page not found (404) Request Method: GET Request URL: http://35527a91f40c4e228d6c464d8a8c8487.vfs.cloud9.eu-west-1.amazonaws.com/ Using the URLconf defined in PollApp.urls, Django tried these URL patterns, in this order:

poll/ admin/ The empty path 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.`

Today I tried to run, But I am getting an error like this. `

CodePudding user response:

Djano errors are self-explanatory, follow its instructions, and are good to go.Also is there the Indentation in your first return ?

from . import views

 urlpatterns = [
 path('', views.index, name='index'),
 ]

CodePudding user response:

You are using regex-syntax with path, you should use the empty string instead:

from . import views

urlpatterns = [
    path('', views.index, name='index'),
]

Furthermore, you use a poll/ prefix here, so that means you either need to visit localhost:8000/poll/, or change this to an empty prefix:

urlpatterns = [
    path('', include('polls.urls')),
    path('admin/', admin.site.urls),
]
  • Related