How to return a value from data base to a function in Django Python?

I’m working in a Python project using Django framework e I’m having some troubles such as: first we have a page to receive a integer value and we submit this value, after we’ll have a new page that contains N integer field, where N is the input value from the first page. Below I show models.py:

class Numero(models.Model):
    n=models.IntegerField()

    def back(self):
        return self.n

class Peso(models.Model):
    peso=models.IntegerField()

    def __str__(self):
        return self.peso

class Preco(models.Model):
    preco=models.IntegerField()

    def __str__(self):
        return self.preco

views.py:

def index(request):
    template=loader.get_template('app/index.html')
    n=0
    if request.method=='POST':
        n = Objetos(request.POST)
    context={'n': n}
    return render(request, 'app/index.html', context)

def valores(request):
    template = loader.get_template('app/valores.html')
    peso=0
    preco=0
    peso_unitario=[]
    preco_unitario=[]
    
    **N=int(n_objetos)**

    for i in range(N):
        if request.method=='POST':
            peso=Peso_Unitario(request.POST)
            preco = Preco_Unitario(request.POST)
            if i == 0:
                peso_unitario = peso
                preco_unitario = preco
            else:
                peso_unitario.append(peso)
                preco_unitario.append(preco)
    context={'peso_unitario': peso_unitario, 'preco_unitario': preco_unitario}
    return render(request, 'app/valores.html', context)

I’m working in a Python project using Django framework e I’m having some troubles such as: first we have a page to receive a integer value and we submit this value, after we’ll have a new page that contains N integer field, where N is the input value from the first page. Below I show models.py:

class Numero(models.Model):
    n=models.IntegerField()

    def back(self):
        return self.n

class Peso(models.Model):
    peso=models.IntegerField()

    def __str__(self):
        return self.peso

class Preco(models.Model):
    preco=models.IntegerField()

    def __str__(self):
        return self.preco

views.py é:

def index(request):
    template=loader.get_template('app/index.html')
    n=0
    if request.method=='POST':
        n = Objetos(request.POST)
    context={'n': n}
    return render(request, 'app/index.html', context)

def valores(request):
    template = loader.get_template('app/valores.html')
    peso=0
    preco=0
    peso_unitario=[]
    preco_unitario=[]
    
    **N=int(n_objetos)**

    for i in range(N):
        if request.method=='POST':
            peso=Peso_Unitario(request.POST)
            preco = Preco_Unitario(request.POST)
            if i == 0:
                peso_unitario = peso
                preco_unitario = preco
            else:
                peso_unitario.append(peso)
                preco_unitario.append(preco)
    context={'peso_unitario': peso_unitario, 'preco_unitario': preco_unitario}
    return render(request, 'app/valores.html', context)

In N=int(n_objetos) **N=int(n_objetos)** is the drouble because I wanna return the value received before.

index.html:

<form action="/app/valores/" method="POST">
    {% csrf_token %}
    <label for="n_objetos">n_objetos:</label>
    <input id="n_objetos" type="number" value=""/><br>
    <label for="peso_maximo">peso_maximo</label>
    <input id="peso_maximo" type="number" value=""/><br>
    <input type="submit">
</form>

<a href="/app/valores/"></a>

valores.html:

<form action="% url 'app:Resultados' %" method="POST">
    {% csrf_token %}
    <label for="peso_u">peso_u</label>;
    <input id="peso_u" type="number" value=""/><br>;
    <label for="preco_u">preco_u</label>;
    <input id="preco_u" type="number" value=""/><br>;
    <input type="submit">;
</form>
<a href="% url 'Resultado' %"></a>

I didn’t write Results.hmtl because it isn’t the real problem. Some errors I received are related to the values are QuerySet or IntegerField, but I want a int value.

Have you worked your way through either the Official Django Tutorial or the Django Girls Tutorial?

The impression I’m getting from the code you’ve posted is that you’re not familiar with the fundamentals of how views, models, forms, and templates all work together to create functional pages.

I think you’ll gain a lot of useful knowledge by taking a step back and working your way through one of those two tutorials. (And by working, I don’t mean just reading them or copy/pasting the code in your editor. To get the most out of them, you should type in the examples and play with them a bit to see what happens.)