Hello this is my urls:
path("cancella_cliente/<int:idclienti>", views.cancella_cliente, name="cancella_cliente"),
my views is as follow:
@require_http_methods(\['POST'\])
def cancella_cliente(request,idclienti):
#tutti = Clienti.objects.filter(id=idcliente).delete()
#return render(request, 'polls/partial/clienti_lista.html', {'tutti': tutti, })
pass
my page is as follow
<dialog id="cancella_cliente" class="modal">
<div class="modal-box">
<h3 class="font-bold text-lg mb-4">Eliminare il cliente {{ dati.ragione }} ID {{ dati.idclienti }}</h3>
<form
hx-post="{% url 'cancella_clienti/dati.idclienti' %}"
hx-target='#contact-table-body'
hx-swap="afterbegin"
hx-on:success="contact_modal.close(); this.reset();"
hx-on:fail="contact_modal.close(); this.reset();"
class="mb-4">
{% csrf_token %}
<br>
<br>
<div class="modal-action">
<button type="button" class="btn"
onclick="cancella_cliente.close()">Cancella</button>
<button type="submit" class="btn btn-primary">Elimina Cliente</button>
</div
></form>
</div>
</dialog>
i get Reverse for ‘cancella_clienti/dati.idclienti’ not found. ‘cancella_clienti/dati.idclienti’ is not a valid view function or pattern name.
How i can pass dati.idclienti to my view???
Side Note: When posting code here, enclose the code between lines of three
backtick - ` characters. Do not use the apostrophe - ', quote -", or any type of “smart quote” character. (I have taken the liberty of correcting this post.
Please remember to do this in the future.)
From the docs for the url tag :
The first argument is a URL pattern name . …
Additional arguments are optional and should be space-separated values that will be used as arguments in the URL.
So you don’t pass the url itself - you pass the name of the url, with the parameters following it.
In this case, you would end up with something like:
hx-post="{% url 'cancella_cliente' dati.idclienti %}"
(This assumes that there’s some object named dati in the context of the template being rendered and that dati can resolve the name idclienti. This also assumes that this url is not namespaced in the app.)
KenWhitesell:
In this case, you would end up with something like:
hx-post="{% url 'cancella_cliente' dati.idclienti %}"
(This assumes that there’s some object named dati in the context of the template being rendered and that dati can resolve the name idclienti. This also assumes that this url is not namespaced in the app.)
sorry but really i don’t understant
just part of the template:
h3 class="font-bold text-lg mb-4">Modifica Cliente {{ idclienti }}</h3>
<form
hx-post="{% url 'salvo_mod_cli' idclienti %}"
hx-target='#contact-table-body'
When i render the page without the hx-post i see in the h3 tag
Modifica Cliente 3
So the var idclienti is correct
But if i add the hx-post i get the reverse error
In the URLs I have :
path("salvo_mod_cli/<int:idclienti>", views.salvo_mod_cli, name="salvo_mod_cli"),
and in the view:
def salvo_mod_cli(request, idclienti):
post = get_object_or_404(Clienti, pk=idcliente)
if request.method == "POST":
form = ClientiForm(request.POST, instance=post)
if form.is_valid():
post = form.save(commit=False)
post.save()
return redirect('tutti_clienti')
else:
pass
Sorry but i don’t understand what is wrong
Thanks
Please post the complete error message, the complete urls.py file contents, and if this is a urls.py file in an app, the contents of the apps.py file for that app.
this is the error that i get
Reverse for 'salvo_mod_cli' with arguments '('',)' not found. 1 pattern(s) tried: ['polls/salvo_mod_cli/(?P<idclienti>[0-9]+)\\Z']
In addition to the other information requested above, please post the complete view that is rendering that template.
This is the view
def salvo_mod_cli(request, idclienti):
if request.method == "POST":
Clienti.objects.filter(pk=idclienti).update(sdi = request.POST['sdi'],
ragione = request.POST['ragione'],
via = request.POST['via'],
piva = request.POST['piva'],
email = request.POST['email'],
iban = request.POST['iban'],
citta = request.POST['citta'],
cap = request.POST['cap'],
prov = request.POST['prov'],
stato = request.POST['stato'],
persona = request.POST['persona'],
tel = request.POST['tel'],
cell = request.POST['cell'])
dati = Clienti.objects.all()
response = render(request, 'polls/partial/contact-row.html', {'dati': dati, })
response['HX-Trigger'] = 'success'
return response
else:
pass
What is the file name of the template that these lines are in?
Whatever the name of it is, it’s the view that is rendering this that I need to see.
sorry the template that render this page is this:
mod_cli_mod.html
dialog id="mod_cli_mod" class="modal">
<div class="modal-box">
<h3 class="font-bold text-lg mb-4">Modifica Cliente {{ idclienti }}</h3>
<form
hx-post="{% url 'salvo_mod_cli' idclienti %}"
hx-target='#contact-table-body'
hx-on:success="mod_cli_mod.close(); this.reset();"
hx-swap="afterbegin"
class="mb-4">
{% csrf_token %}
<div class="form-control w-full">
<label class="label">
<span class="label-text">Ragione Sociale</span>
{{ form.ragione}}
{% if form.ragione.errors %}
<label class="label text-error">
{{form.ragione.errors}}
</label>
{% endif %}
</div>
<br>
<div class="form-control w-full">
<label class="label">
<span class="label-text">P.Iva</span>
{{ form.piva}}
{% if form.piva.errors %}
<label class="label text-error">
{{form.piva.errors}}
</label>
{% endif %}
</div>
<br>
<div class="form-control w-full">
<label class="label">
<span class="label-text">IBAN</span>
{{ form.iban}}
{% if form.iban.errors %}
<label class="label text-error">
{{form.iban.errors}}
</label>
{% endif %}
</div>
<br>
<div class="form-control w-full">
<label class="label">
<span class="label-text">Via</span>
{{ form.via}}
{% if form.via.errors %}
<label class="label text-error">
{{form.via.errors}}
</label>
{% endif %}
</div>
<br>
<div class="form-control w-full">
<label class="label">
<span class="label-text">Città</span>
{{ form.citta}}
{% if form.citta.errors %}
<label class="label text-error">
{{form.citta.errors}}
</label>
{% endif %}
</div>
<br>
<div class="form-control w-full">
<label class="label">
<span class="label-text">CAP</span>
{{ form.cap}}
{% if form.cap.errors %}
<label class="label text-error">
{{form.cap.errors}}
</label>
{% endif %}
</div>
<br>
<div class="form-control w-full">
<label class="label">
<span class="label-text">Provincia</span>
{{ form.prov}}
{% if form.prov.errors %}
<label class="label text-error">
{{form.prov.errors}}
</label>
{% endif %}
</div>
<br>
<div class="form-control w-full">
<label class="label">
<span class="label-text">Stato</span>
{{ form.stato}}
{% if form.stato.errors %}
<label class="label text-error">
{{form.stato.errors}}
</label>
{% endif %}
</div>
<br>
<div class="form-control w-full">
<label class="label">
<span class="label-text">SDI</span>
{{ form.sdi}}
{% if form.sdi.errors %}
<label class="label text-error">
{{form.sdi.errors}}
</label>
{% endif %}
</div>
<br>
<div class="form-control w-full">
<label class="label">
<span class="label-text">Contatto</span>
{{ form.persona}}
{% if form.persona.errors %}
<label class="label text-error">
{{form.persona.errors}}
</label>
{% endif %}
</div>
<br>
<div class="form-control w-full">
<label class="label">
<span class="label-text">Telefono Fisso</span>
{{ form.tel}}
{% if form.tel.errors %}
<label class="label text-error">
{{form.tel.errors}}
</label>
{% endif %}
</div>
<br>
<div class="form-control w-full">
<label class="label">
<span class="label-text">Cellulare</span>
{{ form.cell}}
{% if form.cell.errors %}
<label class="label text-error">
{{form.cell.errors}}
</label>
{% endif %}
</div>
<br>
<div class="form-control w-full">
<label class="label">
<span class="label-text">Email</span>
{{ form.email}}
{% if form.email.errors %}
<label class="label text-error">
{{form.email.errors}}
</label>
{% endif %}
</div>
<br>
<div class="modal-action">
<button type="button" class="btn"
onclick="mod_cli_mod.close()">Cancella</button>
<button type="submit" class="btn btn-primary">Salva Modifiche</button>
</div
></form>
</div>
</dialog>
rafalp
April 21, 2026, 11:50am
12
This line in template should be:
First thing to write to „{% url %}" is what you set in „name=" in your urls.
I need to see the view that is rendering that template, not the template itself.
i semplify but i have the same error:
Views
def cancella_clienti(request,idclienti):
print('passo_da_cancella_clienti')
print('idcliente ,',idclienti)
Clienti.objects.filter(pk=idclienti).delete()
tutti = Clienti.objects.all()
response = render(request, 'polls/partial/contact-row.html', {'tutti': tutti, })
response['HX-Trigger'] = 'success'
return response
urls
path("cancella_clienti/<int:idclienti>", views.cancella_clienti, name="cancella_clienti"),
Template
<td>{{ dati.idclienti }}</td> <td> {{ dati.ragione}} </td><td>{{ dati.piva }}</td><td>{{ dati.sdi }}</td> <td>{{ dati.iban }}</td> <td>{{ dati.via }}</td>
<td>{{ dati.cap }}</td> <td>{{ dati.citta }}</td> <td>{{ dati.prov }}</td>
<td>{{ dati.stato }}</td> <td>{{ dati.persona }}</td> <td>{{ dati.tel }}</td>
<td>{{ dati.cell }}</td> <td>{{ dati.email }}</td>
<td>
{% include 'polls/partial/cancella_cliente.html' %}
<button class="btn btn-primary mb-2 mt-2 ml-2 mr-2" name="{{ dati.idclienti }}" onclick="cancella_cliente.showModal()">Cancella</button>
</td>
<td> {% include 'polls/partial/mod_cli_mod.html' %}
<button class="btn btn-primary mb-2 mt-2 ml-2 mr-2" hx-get="{% url 'mod_cli' dati.idclienti %}" ">Modifica cliente</button></td>
<td><form action="/da_cli_a_for/{{ dati.idclienti }}" method="post"> {% csrf_token %}<button class="btn btn-primary mb-2 mt-2 ml-2 mr-2">Copia in Fornitori</button></form></td>
i render here:
<dialog id="cancella_cliente" class="modal">
<div class="modal-box">
<h3 class="font-bold text-lg mb-4">Eliminare il cliente {{ dati.ragione }} ID {{ dati.idclienti }}</h3>
<form
hx-post="{% url 'cancella_clienti' idclienti=dati.idclienti %}"
hx-target='#contact-table-body'
hx-swap="afterbegin"
hx-on:success="cancella_cliente.close(); this.reset();"
class="mb-4">
{% csrf_token %}
<br>
<br>
<div class="modal-action">
<button type="button" class="btn"
onclick="cancella_cliente.close()">Cancella</button>
<button type="submit" class="btn btn-primary">Elimina Cliente</button>
</div
></form>
</div>
</dialog>
This looks like something different than what we were looking at before.
To keep things from getting confused, please pick one specific view and template that are giving you an error.
Only post information about that one view.
(Also, please label each block of text with the file name - again, to help avoid confusion.)
This is the actual situation to semplify:
views:
def cancella_clienti(request,idclienti):
print(‘passo_da_cancella_clienti’)
print(‘idcliente ,’,idclienti)
Clienti.objects.filter(pk=idclienti).delete()
dati = Clienti.objects.all()
response = render(request, ‘polls/partial/contact-row.html’, {‘dati’: dati, })
response[‘HX-Trigger’] = ‘success’
return response
contact_row.html
<td>{{ dati.idclienti }}</td> <td> {{ dati.ragione}} </td><td>{{ dati.piva }}</td><td>{{ dati.sdi }}</td> <td>{{ dati.iban }}</td> <td>{{ dati.via }}</td>
<td>{{ dati.cap }}</td> <td>{{ dati.citta }}</td> <td>{{ dati.prov }}</td>
<td>{{ dati.stato }}</td> <td>{{ dati.persona }}</td> <td>{{ dati.tel }}</td>
<td>{{ dati.cell }}</td> <td>{{ dati.email }}</td>
<td>
{% include 'polls/partial/cancella_cliente.html' %}
<button class="btn btn-primary mb-2 mt-2 ml-2 mr-2" name="{{ dati.idclienti }}" onclick="cancella_cliente.showModal()">Cancella</button>
</td>
<td> {% include 'polls/partial/mod_cli_mod.html' %}
<button class="btn btn-primary mb-2 mt-2 ml-2 mr-2" hx-get="{% url 'mod_cli' dati.idclienti %}" ">Modifica cliente</button></td>
modal cancella_cliente.html
Eliminare il cliente {{ dati.ragione }} ID {{ dati.idclienti }}
{% csrf_token %}
Cancella
Elimina Cliente
here i have this problem:
when i push the button Elimina Cliente
he execute the function cancella_clienti, but i get the error:
django.urls.exceptions.NoReverseMatch: Reverse for ‘cancella_clienti’ with keyword arguments ‘{‘idclienti’: ‘’}’ not
found. 1 pattern(s) tried: [‘polls/cancella_clienti/(?P[0-9]+)\\Z’]
and the modal never close.
But if i refresh the page the function is execute and the data are deleted.
In this specific situation, the problem here is that the context variable dati is not one object - it’s a QuerySet:
In this case, the expression dati does not have an attribute named idclienti.