- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
无论我以何种方式实现我的表单,我都会收到以下错误。当我转到表单的 URL 时会发生这种情况。
表单.py
class ContactForm(forms.ModelForm):
class Meta:
model = ContactUs
fields = ('name', 'email', 'phone', 'message')
模型.py
class ContactUs(models.Model):
name = models.CharField(max_length=50, blank=True)
email = models.EmailField()
phone = models.CharField(max_length=15, blank=True)
message = models.TextField()
created_at = models.DateTimeField(auto_now_add=True, blank=True, null=True)
class Meta:
verbose_name_plural = "Contact Us"
View .py
def contact(request):
if request.method == "POST":
form = ContactForm(request.POST or None)
errors = None
if form.is_valid():
ContactUs.objects.create(
name = form.cleaned_data.get('name'),
email = form.cleaned_data.get('email'),
phone = form.cleaned_data.get('phone'),
message = form.cleaned_data.get('message'),
created_at = form.cleaned_data.get('created_at')
)
return HttpResponseRedirect("/s/")
if form.errors:
errors = form.errors
template_name = 'contact_us.html'
context = {"form": form, "errors": errors}
return render(request, template_name, context)
网址.py
url(r'^contacts/$', views.ContactForm, name='contact_form'),
html
<form method="POST" class="post-form">{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="save btn btn-warning">Submit</button>
</form>
提前致谢!
最佳答案
您已将 URL 指向表单,而不是 View 。应该是:
url(r'^contacts/$', views.contact, name='contact_form'),
请注意,一旦您修复了此问题,您将遇到另一个问题,因为您的 View 不会为 GET 请求返回任何内容。
关于python - Django - 'ContactForm' 对象没有属性 'get',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45563608/
我有一个在 bootstrap 中制作的联系表。当我检查元素时,我发现它从 .well 类中获取 CSS 属性 在这个类中,背景颜色设置为: background-color: #f5f5f5; 我修
我正在尝试构建一个 e_commerc django 应用程序,但我遇到了一个错误,而且有点令人困惑。我的错误是: Environment: Request Method: GET Request U
无论我以何种方式实现我的表单,我都会收到以下错误。当我转到表单的 URL 时会发生这种情况。 表单.py class ContactForm(forms.ModelForm): class M
我正在尝试使用 flask 创建联系表单,但在呈现页面时不断出现此错误。 'forms.ContactForm object' has no attribute 'hidden_tag' 这是我的文件
任何人都可以分享一些指南、技巧或链接,这些指南、提示或链接是什么构成创建模型的最佳实践的最佳实践,该模型表示没有由数据库中的表备份但仍然可以验证输入的数据的联系表单? 谢谢。 编辑:我忘了提到,如果它
我想使用 JQuery 向 Spring Controller 发送 POST 请求,但我不断从 jquery 收到此错误 Could not read document: Unrecognized
我是一名优秀的程序员,十分优秀!