Новый идентификатор url добавляется после url предыдущего запроса

Я делаю запрос get в django, используя html форму как:

crud.html

<form action="{% url 'crudId' id %}" method="get">
                <div class="col">
                    <div class="form-group" style="width: 20%;margin-top: 5px">
                        <label for="name">Id</label>
                        <input type="number" name="id" value="{% if data %}{{ id }}{% endif %}">
                    </div>
                    <input type="submit" value="OK" style="width: 30%; margin-left: 40%">
                    ...

Мое мнение по этому поводу:

class CrudPageView(View):

    def get(self, request, id=1):
        # get the id from the page
        oid = id
        ...
        # some data and operation
        ...
        return render(request, 'crud.html', {'data': data, 'id': oid})

and in urls.py as :

 path('crud/', CrudPageView.as_view(), name='crud'),
 path('crud/id=<int:id>', CrudPageView.as_view(), name='crudId')
 ...

Итак, http://localhost:8000/crud/ работает как положено и показывает страницу с данными id = 1; когда я ввожу любой id, он также работает как задумано и показывает данные для этого id, но url имеет вид http://localhost:8000/crud/id=1?id=5, а после другого ввода будет http://localhost:8000/crud/id=5?id=12

Что я делаю не так?

Попробуйте что-нибудь вроде этого:

def index(request, id) -> HttpResponse:
    # some data

    return render(request, 'websites/index.html', context={'data': data, 'id': id})


def get(request) -> HttpResponse:
    id_number = request.GET.get('number')
    # some data

    return redirect(index, id=id)
Вернуться на верх