Answer the question
In order to leave comments, you need to log in
The current path, items/12334/, didn't match any of these. How to be?
Hello everyone))
Actually the question is - I'm doing a video course of django. In the course of version 1.1, I have 2.x - that's where the troubles come from.
It is necessary to register the URL so that they are random in the range from 0-9 and there are 4 digits. Help me figure it out - I broke my head ...
application lesson_two
urls.py
from django.urls import path
from . import views
urlpatterns = [
path('' , views.home),
path('items/', views.items, name = 'items'),
path('items/2003/', views.special_case_2003, name = 'special_case_2003'),
path('items/([0-9]{4})', views.year_archive, name = 'year_archive'),
]
from django.shortcuts import render
from django.http import HttpResponse
def home(request):
return HttpResponse('Home Page!')
def items(request):
return HttpResponse('Welcome to localhost/items ')
def special_case_2003(request):
return HttpResponse('Welcome to localhost/items/2003 ')
def year_archive(request):
return HttpResponse('Welcome to localhost/items/([0-9]{4})/ ')
from django.contrib import admin
from django.urls import path, include
from lesson_two import views
urlpatterns = [
# path('', views.home),
# path('admin/', admin.site.urls),
# path('', include('lesson_one.urls')),
path('', include('lesson_two.urls')),
]
Answer the question
In order to leave comments, you need to log in
Or
or
path('items/<int>', views.year_archive, name = 'year_archive'),
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question