Render form and model

Viewed 16

I'm trying render one form and other model. Working only with {"convenio": miConvenio} I have a good result, but I don't know how can send the second value for render on html.

Thanks. Best regards.

def recibo(request):

miConvenio = Convenio()

if request.method=='POST':
    miRecibo= FormularioRecibo(request.POST)
    if miRecibo.is_valid():
        infRecibo = miRecibo.cleaned_data
        
        return render(request, "BieleGastosApp/recibo_impreso.html", {"form": miRecibo}, {"convenio": miConvenio})

else:
    miRecibo = FormularioRecibo()
    #print (miRecibo.mes)

return render(request, "BieleGastosApp/recibo.html", {"form": miRecibo})
1 Answers

You pass a dictionary with two (or more) items, so:

return render(
    request,
    'BieleGastosApp/recibo_impreso.html',
    {'form': miRecibo, 'convenio': miConvenio}  # ← dictionary with two items
)

Note: In case of a successful POST request, you should make a redirect [Django-doc] to implement the Post/Redirect/Get pattern [wiki]. This avoids that you make the same POST request when the user refreshes the browser.

Related