Express和Jade,传入variables
我试图安装这个captcha插件,这是我迄今为止(直接从他们的代码,只是对我的风格调整)
这里是validation码和我下面的步骤: https://github.com/mirhampt/node-recaptcha
: https://github.com/mirhampt/node-recaptcha
在我的router.js
文件中:
app.get('/account/verification/:token/', require('./views/account/verification/index').verifyHuman);
在我的/views/account/verification/index.js
文件中:
exports.verifyHuman = function(req, res, next){ var Recaptcha = require('recaptcha').Recaptcha; var recaptchaKeys = req.app.config.recaptchaKeys; var recaptcha = new Recaptcha(recaptchaKeys.publicKey, recaptchaKeys.privateKey); console.log(recaptcha.toHTML()); //this returns a script tag with an iframe and stuff in it res.render('account/verification/captcha', { layout: false, locals: { recaptcha_form: recaptcha.toHTML() } }); };
然后我的/views/account/verification/captcha.jade
文件:
div#captcha script(type='text/template', id='tmpl-captcha-verification') form#captcha-verification #{recaptcha_form} button.btn.btn-primary.btn-captcha-verification(type='button') Check Captcha
我无法得到它显示validation码的脚本。 它没有定义,但以一种奇怪的方式出现。 这是我的控制台中显示的内容:
<script type="text/template" id="tmpl-captcha-verification"><form id="captcha-verification"><undefined></undefined><button type="button" class="btn btn-primary btn-captcha-verification">Check Captcha</button></form></script>
我甚至可以尝试#{layout}
,并在控制台中得到这个:
<script type="text/template" id="tmpl-captcha-verification"><form id="captcha-verification"><false></false><button type="button" class="btn btn-primary btn-captcha-verification">Check Captcha</button></form></script>
这就像翡翠试图格式化它,但其中一个主要问题是,它是未定义的,当我的/views/account/verification/index.js
文件,我console.log
的variables不是。
此外,请注意,如果我这样做!= recaptcha_form
,它只是显示在HTML中的forms,因为如果这!= recaptcha_form
代码甚至没有。
我已经search了这个答案的其他问题,我仍然很困惑。 任何帮助将不胜感激。 谢谢