问题
I've tried to build the simplest possible form in Sprox using pyramid.
# model.py
class Allocation:
# some fields ...
class SproxForm(AddRecordForm):
__model__ = Allocation
sprox_form = SproxForm(DBSession)
# views.py
def sprox_form(request):
return {'f':sprox_form,'kw':{}}
<html>
<body>
<div tal:content="structure f(kw)"/>
</body>
</html>
But it just prints out {'kw': {}, 'f': }
The forms tutorial is written using TurboGears2 and I am unable to translate it to pyramid, because I am new to pyramid.
So could someone tell me what am I doing wrong, or show me a short (but complete) example, which uses pyramid?
回答1:
Well your form is named sprox_form
and your view is named sprox_form
. This ambiguity is gonna be a bad idea. Other than that I can't see anything suspicious, assuming your chameleon syntax is correct. If you were using mako it'd be simply ${f(kw)}
although instead of f
I might suggest using the name widget
or form
, and instead of kw
maybe value
or form_input
.
来源:https://stackoverflow.com/questions/14419400/the-hello-world-of-sprox-with-pyramid