J
J
Juvel19882020-10-27 23:33:17
Django
Juvel1988, 2020-10-27 23:33:17

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

1 answer(s)
D
Dr. Bacon, 2020-10-28
@bacon

1. already learn how to insert code into the code tag
2. is it written in the book like this ? If yes, then throw it away. Or have you already corrected this line to the wrong one? path(r'^$', views.index, name='index')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question