Answer the question
In order to leave comments, you need to log in
Can't create a home page. What am I doing wrong?
Good evening. Explain what I'm doing wrong? I'm learning Django from a book by Eric Matiz. I create a home page at localhost:8000
To do this, in the project's learning_log folder, I edit the urlsl.py file as follows:
<i>from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin .site.urls),
path(r'', include('learning_logs.urls'))
]
Then in a subfolder I create a file with the same name urlsl.py and write the following in it:
from django.urls import path
from . import views
urlpatterns = [
path(r'^$', views.index, name='index')
]
Next, I make the view in views.
from django.shortcuts import render
def index(request):
return render(request, 'learning_logs/index.html')
# Create your views here.
I create index.html in the right folder with the text I need, but the server gives a 404 error at the output. The full text of the error:
Page not found (404)
Request Method: GET
Request URL: localhost:8000
Using the URLconf defined in learning_log.urls, Django tried these URL patterns, in this order:
admin/
^$ [name='index']
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.
I beg you: explain what my mistake is and tell me how to fix it.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question