0

I want to print a list called formulario and I want to paste them into a html file using Django template language, although I'm not able to display that information in <li> tag. Is there sth am I missing?

views.py

from django.template import RequestContext
from django.http import HttpResponse
from django.shortcuts import render
import pandas as pd

formulario = ["Hola", "Hi"]

def formulario(request):
        return render (request, "formulario/formulario.html",{
            "formulario":formulario
        })

Html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>Formulario !</h1>

    <ul>
        {% for formulario in formulario %}
            <li>{formulario}</li>
        {% endfor %}
    </ul>
</body>
</html>

urls.py

from django.urls import path
from . import views

urlpatterns = [
    
    path("index.html",views.index, name="index"),
    path("financierofinanciamiento.html",views.financiamiento, name="financiamiento"),
    path("financierobeneficio.html",views.beneficio, name="beneficio"),
    path("tecnicoinfra.html",views.infra, name="infra"),
    path("tecnicoequipo.html",views.equipo, name="equipo"),
    path("tecnicoherramientas.html",views.herramientas, name="herramientas"),
    path("tecnicomateriaprima.html",views.materiaprima, name="materiaprima"),
    path("formulario.html",views.formulario, name="formulario"),  
]
1
  • It has to be <li>{{ formulario }}</li> Commented Jun 17, 2021 at 16:43

1 Answer 1

2
  {% for item  in formulario %}
        <li>{{ item }}</li>
    {% endfor %}
Sign up to request clarification or add additional context in comments.

3 Comments

I don't know what you did but it works, for some reason when I put instead of "item" formulario" it doesn't work. Don't know why, but at least your solution works, Thanks !
The item name cant have the same name as the list.
Great info ! Thanks !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.