S
S
SuperiorAId2021-06-09 22:14:02
Django
SuperiorAId, 2021-06-09 22:14:02

There is an error when rendering the form in the template, what's wrong?

error when drawing the form in the template:


Reverse for 'sensortoroom' with no arguments not found. 1 pattern(s) tried: ['sensortoroom/(?P[0-9]+)$']


the form itself:
template
<form action="{% url 'addsensor' %}" method="post">
{% csrf_token %}
{{form.as_p }}

<button type="submit">Save</button>

</form>


urls.py
urlpatterns = [
...
    path('sensortoroom/<int:room_id>', sensortoroom, name='sensortoroom'),
...
]


view.py
def sensortoroom(request, room_id):
    room = Rooms.objects.filter(id=room_id)
    return render(request, 'room/addsensortoroom.html', {'room': room})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Melnikov, 2021-06-10
@SuperiorAId

Well, look ...
You just have the sensortoroom pattern in the urls
in the function 2 arguments, 1 of them is the room ID
Perhaps you really want to see the ID in the jang patterns?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question