variable from template to view

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

variable from template to view

Luca Bertolotti
Hello
i have a question:
This is the template:
{% load static %}
<head>
<link rel="stylesheet" href="{%static "regole.css" %}">
</head>
<div id= "taba">
    <table>
        
        <tr class="prima">
            <td>ID</td> <td>Ragione Sociale</td> <td>Via</td> <td>Cap</td> <td>Città</td> <td>Provincia</td> <td>Stato</td> <td>Contatto</td> <td>Tel.Fisso</td> <td>Tel.Cellulare</td> <td>Email</td>
        </tr>
        
        {% for dati in tutti %}
                <tr class={% cycle 'odd' 'even' %}>
            <td>{{ dati.idclienti }}</td> <td>{{ dati.ragione}}</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><form action="canc_cli/{{ dati.idclienti }}" method="post"> {% csrf_token %}<button type="submit">Delete</button></form></td>
            </tr>
        {% endfor %}
    </table> 
</div>


When i click kon the button he call the funciorn canc_cli from the view file:

from django.shortcuts import render
from .models import Clienti

def tutti_clienti(request):
    tutti = Clienti.objects.all()
    return render(request, "polls/tutti_clienti.html", {"tutti": tutti})

def canc_cli(request, idcliente):
    print('luca :'+str(idcliente))
    Clienti.objects.filter(pk=idcliente).delete()
    tutti = Clienti.objects.all()
    return render(request, "polls/tutti_clienti.html", {"tutti": tutti})

Than he to the right job, but if i push the button again he search for the url "canc_cli/canc_cli/{{ dati.idclienti" the is not un my urls the problem is because when i do the first time the button function he never refereah the url in the browser instead of tutti_clienti.html in the browser i have canc_cli/idcliente 

Can you help me to solve the problem

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e0306deb-405d-471c-a39b-171c1dede911%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: variable from template to view

Luca Bertolotti


Hello again
I have solved with this:

def canc_cli(request, idcliente):
    print('luca :'+str(idcliente))
    Clienti.objects.filter(pk=idcliente).delete()
    return redirect('tutti_clienti')

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a9e29eba-dd7c-4a12-bf48-f53b5d2cfa36%40googlegroups.com.