我尝试使用django& amp; bootstrap,在其中一个页面中我有两个表单,一个是为帖子添加注释,另一个是与我联系,联系表单是在bootstrap模式上。如何使用基于函数的视图将联系表单放在模态中?
views.py
def GameView(request, slug):
game = GameUpload.objects.get(slug=slug)
comment_form = CommentForm()
contact_form = ContactForm()
if request.method == "POST":
if request.POST['form-type'] == u'comment-form':
comment_form = CommentForm(request.POST)
if comment_form.is_valid():
instance = form.save(commit=False)
instance.upload = game
instance.save()
else:
contact_form = ContactForm(request.POST)
#Send mail to me
context = {"game": game,
"comment_form": comment_form,
"contact_form": contact_form,
"comments": game.comment_set.all().order_by("-date")}
return render(request, 'game.html', context)
模板
<div class="jumbotron">
<div class="container">
<div class="col-sm-8 col-sm-offset-2">
<h3><i class="fa fa-comment"></i> Add Comment:</h3>
<form method="POST">
{% csrf_token %}
{{ comment_form|crispy }}
<input type="hidden" name="form-type" value="comment-form" />
<input type="submit" value="Submit" class="btn btn-primary" />
</form>
</div>
</div>
</div>
模态:
<div id="contact" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Contact Me</h4>
</div>
<div class="modal-body">
<form method="POST" action="/">
{% csrf_token %}
{{ contact_form|crispy }}
<input type="hidden" name="form-type" value="contact-form" />
</form>
</div>
<div class="modal-footer">
<input type="submit" value="Send" class="btn btn-success" />
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
答案 0 :(得分:1)
模型提交按钮应位于表单标记
内<h2>Where (Location / Station)</h2>
<label for="selwhere">Select the locations for the job type selected above</label>
<select name="selwhere" id="selwhere" multiple="multiple">
<option value="linecook">Line cook</option>
<option value="barrista">Barrista</option>
<option value="securityguard">Security Guard</option>
<option value="fignipper">Nipper of Figs</option>
</select>