Answer the question
In order to leave comments, you need to log in
Why doesn't the URL match the pattern?
Django says it doesn't match the pattern. If I entered incorrectly, then write an example of the correct input and write the correct code. ?P\ cannot be used properly. I need the result I need.
URLs.py:
from django.contrib import admin
from django.urls import path
from django.urls import re_path
from firstapp import views
urlpatterns = [
path('', views.index, name = "home"),
path('products/<str:productName>', views.products),
path('users/<int:id>/<str:name>', views.users)
]
from django.http import HttpResponse
from django.shortcuts import render
def index(request):
return HttpResponse("<h1>Главная</h1>")
def products(request):
genre = request.GET.get("genre", "")
productName = request.GET.get("name", "")
return HttpResponse("Продукт - {0}, Категория: {1}".format(productName, genre))
def users(request, id=123, name="Зубенко Михаил"):
id = request.GET.get("id", 1)
name = request.GET.get("name", "Tom")
return HttpResponse("id: {0}.<br>Имя: {1}".format(id, name))
Answer the question
In order to leave comments, you need to log in
These are parameters that are specified through a question mark.
Correct input:
127.0.0.1:8000/users/?id=12121&name=smadjl
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question