D
D
Dmitry Sergeev2019-04-13 18:42:11
Django
Dmitry Sergeev, 2019-04-13 18:42:11

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'),
]

views.py
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})/ ')

project folder courses_django
urls.py
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')),
]

The error constantly falls out
on the screen is shown
5cb202d1edc4d145936483.jpeg
Tired of beating - help with advice ....

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2019-04-13
@strannic123

Or
or

path('items/<int>', views.year_archive, name = 'year_archive'),

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question