Reputation: 1
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!")
Upvotes: 0
Views: 187
Reputation: 13047
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),
]
Upvotes: 1