【发布时间】:2017-01-27 01:03:34
【问题描述】:
我一直在通过Django forms 'tutorial'。阅读完本教程后,我尝试对其进行修改以满足我的需要并对其进行自定义以很好地学习 Django 表单。我发现每当我修改表格时,网站都不会更新。我认为我的代码有错误,但我无法找到它。
# views.py
def contact(request):
# if this is a POST request we need to process the form data
if request.method == 'POST':
# create a form instance and populate it with data from the request:
form = ContactForm(request.POST)
# check whether it's valid:
if form.is_valid():
# process the data in form.cleaned_data as required
# ...
# redirect to a new URL:
return HttpResponseRedirect('/message_recived/')
# forms.py
from django import forms
class ContactForm(forms.Form):
name = forms.CharField(label='Name', max_length=100)
email = forms.EmailField(label='Email', max_length=100)
message = forms.CharField(label='Message', max_length=500)
# models.py
from django.db import models
class Contact(models.Model):
name = models.CharField(max_length=100)
email = models.CharField(max_length=100)
message = models.CharField(max_length=500)
这是contact.html 模板:
#contact.html
{% extends "BlogHome/headerAndFooter.html" %}
{% block content %}
<script>
document.title = "Pike Dzurny - Contact"
</script>
<form action="/message_recived/" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit" />
</form>
{% endblock %}
我做错了吗?我已经尝试清除浏览器缓存,使用新浏览器,显然是刷新它。
【问题讨论】:
标签: python django django-models django-1.8