ValueError: dictionary update sequence element # 0 has length 1; 2 is required

1

I'm trying to make a web program, but the moment I want to throw the message I get the following error:

ValueError: dictionary update sequence element # 0 has length 1; 2 is required

My code is as follows:

from jinja2 import Environment, FileSystemLoader
def name_com(nombre):
    env = Environment(loader=FileSystemLoader("C:\Users\ESantana\Documents\PruebaHMTL"))
    template = env.get_template("index.html")
    apellidos="Santana Barcenas"
    completo =nombre+apellidos
    print(completo)
    html, = template.render(completo)
    print(html)

if __name__ == '__main__':
    nombre='Edwin '
    name_com(nombre)

& in my HTML so I am receiving the string

<p {{completo}} </p>
    
asked by Pony94 06.04.2018 в 17:05
source

1 answer

0

The problem is that you give the render method a positional argument (the string completo ) when you wait for a dictionary.

From the Jinja2 documentation :

  

This method accepts the same arguments as the constructor dict: A dict, a dict subclass or some keyword arguments.

That is, this method accepts the same arguments as the constructor of dict , an instance of dict or a subclass of this or a kind of arguments of type keyword .

Or you pass arguments by name:

html = template.render(completo=completo)

Or you pass a dictionary directly:

html = template.render({"completo": completo})

The key in the dictionary or the name of the argument corresponds to the one used in the template.

  

Note: As commented by @alanfcn the comma in html, = will cause a ValueError when trying to unpack two values from the render return method, which only returns the template rendered as a unicode string.

    
answered by 06.04.2018 / 18:11
source