Я изучаю главу 18 18.4.2 в Python Cra sh Курс, когда я открываю http://localhost: 8000 / топики , я использую Django 3.0 и python 3.8 показывает
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/topics
Using the URLconf defined in learning_log.urls, Django tried these URL patterns, in this order:
admin/
[name='index']
The current path, topics, 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.
, и это мой код learning_log \ urls.py
from django.contrib import admin
from django.urls import path
from learning_logs import views
urlpatterns = [
path('admin/', admin.site.urls),
path('',views.index,name = 'index')
]
learning_logs \ urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$',views.index,name = 'index'),
url(r'^topics/$',views.topics,name='topics')
]
views.py
from django.shortcuts import render
from .models import Topic
# Create your views here.
def index(request):
return render(request,'learning_logs/index.html')
def topics(request):
topics = Topic.objects.order_by('date_added')
context = {'topics':topics}
return render(request,'learning_logs/topics.html',context)
base. html
<p>
<a href="{% url 'learning_logs:index' %}">Learning Log</a>-
<a href="{% url 'learning_logs:topics'%}">Topics</a>
</p>
{% block content %}{% endblock content %}
themes. html
{% extends "learning_logs/base.html" %}
{% block content %}
<p>Topics</p>
<ul>
{% for topic in topics %}
<li>{{ topic }}</li>
{% empty %}
<li>No topics have been added yet.</li>
{% endfor %}
</ul>
{% endblock content %}
и runserver показывает:
Not Found: /topics
[06/Jan/2020 17:53:15] "GET /topics HTTP/1.1" 404 2077
введите описание изображения здесь