How to get different names in request.post method

I got a problem, I'm making a web for SQLServer Agent Jobs execution, where if my job got parameters it redirects me to another page where I can enter my parameters. My problme is submiting these parameters. I don't know how to send all the parameters from my html to my view.py. All inputs have different names and I really don't know how to make the request accept different input names. I'll add some code below. IM commenting the line where I have the problem

parameters.html

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{% block title %} Parametros {% endblock %}</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
</head>

<div class="container">
    <div class="row">
        <div class="col-md-4 offset-md-4">
            <br><br>
            <div class="card">
                <div class="card-header">
                    <h3>Parámetros</h3>
                </div>
                <div class="card-body">
                    <form method="post">
                        {% csrf_token %}
                        {% for i in parameters %}
                        <!-- Parameters input -->
                        <div class="form-outline mb-4">
                            <label class="form-label" for="form2Example1">{{ i.parameter_name }}</label>
                            {% if i.parameter_type == 'Int' %}
                            <input type="number" id="form2Example1" class="form-control" name="int" />
                            {% else %}
                            {% if i.parameter_type == 'Decimal' %}
                            <input type="text" id="form2Example1" class="form-control" name="decimal" />
                            {% else %}
                            {% if i.parameter_type == 'String' %}
                            <input type="text" id="form2Example1" class="form-control" name="string" />
                            {% else %}
                            {% if i.parameter_type == 'Date' %}
                            <input type="date" id="form2Example1" class="form-control" name="date" />
                            {% endif %}
                            {% endif %}
                            {% endif %}
                            {% endif %}
                        </div>
                        {% endfor %}
                        <!-- Submit button -->
                        <button type="submit" class="btn btn-primary btn-block mb-4">Ejecutar</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

views.py

#job execution
def ejecutar(request, job_name):
    cursor = connection.cursor()
    job = Jobs.objects.get(job_name=job_name)
    if job.flag_params == 0:
        cursor.execute("EXEC msdb.dbo.sp_start_job '" + job.job_name + "'")
        return HttpResponse("""<html><script>alert("Job ejecutado");window.location.replace('/home');</script></html>""")
    else:
        #redirects to parameters.html
        redirect('parameters.html', job_name=job.job_name)
        #get job parameters
        parameters = Parametros.objects.filter(job_id=job.id)
        if request.method == 'POST':    
            for parameter in parameters:
                #update parameters
                #Here I got the problem, in request.POST(), how can I get different input names from parameters.html (decimal, int, string, date)
                cursor.execute("UPDATE Jobs_parametros SET parameter_value='" + request.POST['decimal'] + "' WHERE parameter_name='" + parameter.parameter_name + "' AND job_id='" + str(job.id) + "'")
            cursor.execute("EXEC msdb.dbo.sp_start_job '" + job.job_name + "'")
            return HttpResponse("""<html><script>alert("Job ejecutado");window.location.replace('/home');</script></html>""")
        return render(request, 'parameters.html', {'parameters': parameters})

models.py

class Usuarios(models.Model):
    id = models.AutoField(primary_key=True)
    username = models.CharField(max_length=100)

class Jobs(models.Model):
    id = models.AutoField(primary_key=True)
    job_name = models.CharField(max_length=100)
    flag_activo = models.BooleanField(default=True)
    flag_params = models.BooleanField(default=False)

class DetailJobUser(models.Model):
    id = models.AutoField(primary_key=True)
    user = models.ForeignKey(Usuarios, on_delete=models.CASCADE)
    job = models.ForeignKey(Jobs, on_delete=models.CASCADE)

class Parametros(models.Model):
    id = models.AutoField(primary_key=True)
    job = models.ForeignKey(Jobs, on_delete=models.CASCADE)
    parameter_name = models.CharField(max_length=100)
    parameter_type = models.CharField(max_length=100)
    parameter_value = models.CharField(max_length=100)

Thanks for your answers :D

Back to Top