Django 使用无javascript的引导模式提交表单?

Django 使用无javascript的引导模式提交表单?,django,twitter-bootstrap,modal-dialog,Django,Twitter Bootstrap,Modal Dialog,我正在开发一个django应用程序,我正在尝试使用引导模式来显示和提交一个存储在单独html文件中的表单。我在表单中显示了模式,我可以按下保存按钮,它关闭模式并重定向(尽管页面显示为空白,即使它是正确的url)。我也在使用crispy表单,所以按钮是通过它工作的,而不是放在我的模式中 我对javascript没有任何经验,所以我希望使用bootstrap可以避免使用它,而且一定有办法,对吧 我知道我的表单可以工作,因为当我在模式之外加载html文件时,我可以保存我的表单,它会正确地重定向到主页面

我正在开发一个django应用程序,我正在尝试使用引导模式来显示和提交一个存储在单独html文件中的表单。我在表单中显示了模式,我可以按下保存按钮,它关闭模式并重定向(尽管页面显示为空白,即使它是正确的url)。我也在使用crispy表单,所以按钮是通过它工作的,而不是放在我的模式中

我对javascript没有任何经验,所以我希望使用bootstrap可以避免使用它,而且一定有办法,对吧

我知道我的表单可以工作,因为当我在模式之外加载html文件时,我可以保存我的表单,它会正确地重定向到主页面,但在模式中它不工作

触发模式的按钮

<button type="button" class="btn btn-primary btn-small" data-toggle="modal" href="new/" data-target="#newExpense" style="margin-left:15px;margin-top:20px">Add Expense(m)</button>
视图功能

def new(request, template='expenses/new.html'):
  if request.method == 'POST':
    new_expense = ExpenseForm(request.POST)
  if new_expense.is_valid() and new_expense.clean():
    new_expense.save()
    return HttpResponseRedirect('/')
  else:
    new_expense = ExpenseForm()

  return render(request, template, {'new_expense':new_expense})

(很抱歉,如果那里有没有有用的代码,或者我缺少有用的代码)

不幸的是,你不能在这里转义Javascript(ajax)——引导是用Javascript实现的,所以如果你需要一个模式表单submit,就不能转义JS。哦,poop,谢谢,我想我需要研究一下JS/ajax
class ExpenseForm(forms.ModelForm):

class Meta:
  model = Expense
  fields = ['date', 'store', 'price', 'payment_type', 'category']
  widgets = {
    'date': forms.DateInput,
  }

def __init__(self, *args, **kwargs):
  self.helper = FormHelper()
  self.helper.form_id = 'id-expenseForm'
  self.helper.form_method = 'POST'
  self.helper.form_class = 'form-horizontal'
  self.helper.help_text_inline = True

  self.helper.layout = Layout(
    Fieldset(
      '',
      'date',
      'store', 
      'price', 
      'payment_type',
      'category', 
      ),
    FormActions(
      Submit('save', 'Save'),
      Reset('reset', 'Reset'),
      )
    )
  super(ExpenseForm, self).__init__(*args, **kwargs)
def new(request, template='expenses/new.html'):
  if request.method == 'POST':
    new_expense = ExpenseForm(request.POST)
  if new_expense.is_valid() and new_expense.clean():
    new_expense.save()
    return HttpResponseRedirect('/')
  else:
    new_expense = ExpenseForm()

  return render(request, template, {'new_expense':new_expense})