Let me ask about a python pyramid framework. I want to perform the logic (inspection, registration, redirection) of the form to display with all pages in one place of the view. I use the panel of pyramid_layout, but the panel cannot return HTTPFound(). It seems to be able to come true in hook or javascript, but is there not the good method?
- pyramid==1.4.5
- WTForms==1.0.5
Thanks, comment.
this is common footer with feedbackform.
app/tempaltes/layouts/layout.mako
${panel('navbar')}
${next.body()}
<!-- common footers -->
<div class="container">
${panel('common_footers')}
<div class="col-lg-5">
<p>Please drop us a line on Project.</p>
<form id="feedback" action="${action}" method="post">
<div class="form-group${' has-error' if form.feedback.errors else ''}">
${form.feedback(class_="form-control", rows="4", maxlength="140")}
</div>
% if form.feedback.errors:
<div class="form-group has-error">
<p class="text-danger">
% for error in form.feedback.errors:
${error}
% endfor
</p>
</div>
% endif
<div class="form-group">
<button type="submit" class="btn btn-primary">Send us a feedback</button>
</div>
</form>
</div>
</div><!--/.container -->
and this is views.py
app/views.py
@view_config(route_name = 'home', renderer = '/home.mako')
def home(request):
form = Feedback(request.POST)
url = request.current_route_url()
if request.method == 'POST' and form.validate():
return HTTPFound(location = url)
return dict(form = form, action = url)
def foo(request):
... same code
def bar(request):
... same code
It cannot be necessary to write the same code to a function in view.py many times. Is it wrong?