N
N
Nikolai Getmanov2020-11-01 21:32:49
Django
Nikolai Getmanov, 2020-11-01 21:32:49

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


views.py:
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))


Help me please. The URL I entered is 127.0.0.1:8000/users/id=12121/name=smadjl

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dr. Bacon, 2020-11-01
@bacon

127.0.0.1:8000/users/12121/smadjl

S
soremix, 2020-11-01
@soremix

id=and name=remove from url

N
Nikolay Getmanov, 2020-11-02
@Kolya_Get

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 question

Ask a Question

731 491 924 answers to any question