Pregunta

Había configurado Pylons V0.9.7, y creé un proyecto usando Genshi. Traté de codificar un caso de prueba fácil, pero no funciona.

Código: Member.py

coding: utf-8 
import logging import foo.model

from foo.lib.base import *

log = logging.getLogger(__name__)

class MemberController(BaseController):

    def index(self):
        c.title="title"
        c.mes="message"
        return render('test.html')

Código: Test.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:py="http://genshi.edgewall.org/"
      lang="ja">
    <head>
        <title>${c.title}</title>
    </head>
<body>
    <p>${c.mes}</p>
</body>
</html>

y mensaje de error (en el registro)

Error - <type 'exceptions.NameError'>: global name 'c' is not defined

Por favor, ayúdame a encontrar el error.

¿Fue útil?

Solución

    c.title="title"

requiere nombre c para definirse (globalmente o localmente). Nunca defines cualquier cosa nombrada c.

Entonces, defina un nombre adecuado c (uno donde atribuye title se puede configurar!) Antes de asignar algo a c.title!

Siguiente pista: from pylons import tmpl_context as c - no lo hiciste hacer que from ... import ... as, ¿Sabías?-)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top