0
votes

I setup webpage via cmd for Django.However, i had problem when accessing index page of 127.0.0.1:8001. I tried to update urls.py but still have problem.

Browser page error: Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8001/index Using the URLconf defined in barry.urls, Django tried these URL patterns, in this order:

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

urls.py file:
"""{{ project_name }} URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/{{ docs_version }}/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.conf.urls import url
from sign import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('index/', views.index),
]
views.py
from django.shortcuts import render

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

1
Can you add your apps, urls and views here??Astik Anand
Post your project directory structure.Astik Anand
Actually, i just installed python 37 and install django. I tried the steps to runserver (maange.py runserver 127.0.0.1:8080) and update above URLS + views. How to get the project directory structure.Barry Yu

1 Answers

1
votes

You are mistaking in path pattern. Confusing with path, re_path and url.

Have a look at documentation Django Urls - Path.

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