我使用的是Python金字塔和Jinja2模板。我想将表单数据保存到会话中,并在另一个HTML页面中检索它。如何更改才能传递数据?我只知道如何存储我输入的数据视图.py像这样进入会话request.session['postal'] = 01934
,但这不是我输入的数据交货.jinja2. 如果我使用print (session['postal'])
,这将只显示在我的命令提示符中,而不会显示在HTML页面中。有人能帮我吗?我是个初学者。在
在我的Views.py?在
我的HTML:交货.jinja2在
<form class="form-horizontal" method="POST">
<div class="form-group">
<label class="control-label col-md-2" for="postal">Postal Code:</label>
<input type="text" class="form-control" id="postal" placeholder="Enter Postal Code" name="postal" />
</div>
<div class="form-group">
<label class="control-label col-md-2" for="address">Detailed Address:</label>
<textarea class="form-control" rows="3" id="address" placeholder="Enter Address" name="address"></textarea>
</div>
<div class="form-group">
<label class="control-label col-md-2" for="unit">Unit No #:</label>
<input type="text" class="form-control" id="unit" placeholder="Enter Unit No" name="unit" />
</div>
<button type="submit" class="btn btn-default" name="submit">Submit</button>
</form>
在视图.py在
^{pr2}$我希望之前输入的数据显示在这个确认页面上:确认.jinja2在
<form class="form-horizontal" method="POST">
<div class="form-group">
<label class="control-label col-md-2" for="postal">Postal Code:</label>
<input type="text" class="form-control" id="postal" name="postal" />
</div>
<div class="form-group">
<label class="control-label col-md-2" for="address">Detailed Address:</label>
<textarea class="form-control" rows="3" id="address" name="address"></textarea>
</div>
<div class="form-group">
<label class="control-label col-md-2" for="unit">Unit No #:</label>
<input type="text" class="form-control" id="unit" name="unit" />
</div>
</form>
我想,你可以把帖子从初始表单传递到确认页面的模板上,不需要会话。在
如果您需要会话,可以从模板调用它
<input type="text" class="form-control" id="postal" name="postal" value="{{session['postal']}}" />
相关问题 更多 >
编程相关推荐