【发布时间】:2014-10-07 22:44:10
【问题描述】:
我无法让 Submit 与crispy-froms 一起使用。带有引导程序的普通 django 表单可以正常工作。我已经尝试了所有我能找到的教程,但目前无法找到代码有什么问题。
点击 sumbit 时,它会打开我的客户概览页面,但没有添加新客户。此处未显示所有字段,但字段设置均设置为允许空值。
我的模型.py
from django.db import models
from django.utils.encoding import smart_unicode
class CustomerType(models.Model):
customer_type = models.CharField(max_length=120, null=True, blank=True)
timestamp_created = models.DateTimeField(auto_now_add=True, auto_now=False)
timestamp_updated = models.DateTimeField(auto_now_add=False, auto_now=True)
def __unicode__(self):
return smart_unicode(self.customer_type)
class Customer(models.Model):
customer_type = models.ForeignKey(CustomerType, null=True, blank=True)
customer_name = models.CharField(max_length=120, null=True, blank=True)
我的意见.py
def customercrispy(request):
form = ExampleForm()
return render_to_response("customer-crispy.html",
{"example_form": form},
context_instance=RequestContext(request))
我的表单.py
from django import forms
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Fieldset, ButtonHolder, Submit, Div, Field
from crispy_forms.bootstrap import TabHolder, Tab, FormActions
from .models import Customer
class CustomerAddForm(forms.ModelForm):
class Meta:
model = Customer
class ExampleForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(ExampleForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.form_method = 'post'
self.helper.form_action = '/customeroverview/'
self.helper.add_input(Submit('submit', 'Submit'))
class Meta:
model = Customer
编辑:打开表单时的 CMD 输出
[08/Oct/2014 12:45:12] "GET /customercrispy/ HTTP/1.1" 200 11203
[08/Oct/2014 12:45:12] "GET /customercrispy/static/js/ie-emulation-modes-warning.js HTTP/1.1" 404 3118
[08/Oct/2014 12:45:12] "GET /assets/js/ie10-viewport-bug-workaround.js HTTP/1.1" 404 3079
保存时输出CMD
[08/Oct/2014 12:46:52] "POST /customeroverview/ HTTP/1.1" 200 5129
[08/Oct/2014 12:46:52] "GET /customeroverview/static/js/ie-emulation-modes-warning.js HTTP/1.1" 404 3124
[08/Oct/2014 12:46:52] "GET /assets/js/ie10-viewport-bug-workaround.js HTTP/1.1" 404 3079
【问题讨论】:
-
您在服务器端遇到了哪些错误(如果有)?如果通过“终端”或 CL 运行服务器,您可以分享提交表单后从那里获得的输出吗?另外,您是否尝试过从前端诊断任何问题(通过浏览器终端中的错误)?
-
-
嗨,乔,我在问题中添加了终端输出。保存时浏览器没有显示任何错误 - 我在 settings.py 中启用了 no Debug 选项
标签: python django twitter-bootstrap django-crispy-forms