我想用Crispy Forms
使我的表單看起來不錯。我在forms.py
如下:Django脆皮表單提交按鈕
from django import forms
from .models import Team
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit, Layout, Field
from crispy_forms.bootstrap import (
PrependedText, PrependedAppendedText, FormActions)
class CreateTeamForm(forms.ModelForm):
class Meta:
model = Team
fields = [ 'Project_name', 'Project_number'
]
helper = FormHelper()
helper.add_input(Submit('submit', 'Submit', css_class='btn-primary'))
helper.form_method = 'POST'
然後在我的views.py
:
def create_team(request):
if request.method == 'POST':
form = CreateTeamForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return render('/teams/my_team.html',{''})
else:
form = CreateTeamForm()
return render(request, 'teams/team_form.html', {'form':CreateTeamForm()})
最後,在我的模板:
{% extends "main/base.html" %}
{% load crispy_forms_tags %}
{% block content %}
<div class="row">
<div class="jumbotron">
{% crispy form %}
</div>
</div>
{% endblock %}
然而,我的提交按鈕,我叫ISN」 t正在顯示。我已經閱讀了cripsy的形式文檔,我似乎無法發現我的實現有什麼問題。顯示除提交按鈕以外的所有內容。有任何想法嗎?