我的应用程序模型包含三个字段。第一个将与邮件应用程序共享,作为邮件目的地;第二个将与aps应用程序共享,作为页面显示的图形频率索引.html. 我想我已经很接近了,但是当我在终端中写入命令“runserver”时,它显示了以下错误:
"needs updating." % name django.core.exceptions.ImproperlyConfigured: Creating a ModelForm without either the 'fields' attribute or the 'exclude' attribute is prohibited; form ConfigurationFrorm needs updating.
这是我的密码,你知道我做错了什么吗??你知道吗
项目/选项/视图.py你知道吗
from django.shortcuts import render
from choix.forms import ConfigurationForm
from django.http import HttpResponse, HttpResponseRedirect
from django.core.urlresolvers import reverse
from choix.models import Configuration
from django import forms
class Meta:
model = Configuration
def index(request):
if request.method == 'GET' :
form = ConfigurationForm()
args = {}
args.update(csrf(request))
args['form'] = form
return render_to_response('create_article.html', args)
else:
form = ConfigurationForm(request.POST)
if form.is_valid():
e_mail = form.e_mail.data['e_mail']
temps = form.temps.data['temps']
temperature = form.temperature.data['temperature']
post = m.Post.objects.create(e_mail=e_mail,
temps=temps, temperature = temperature)
post.save()
return HttpResponseRedirect(reverse('post_detail', kwargs={'post_id' : post.id}))
return render(request, 'choix/configuration.html', {'form': form})
项目/aps/视图.py你知道吗
from django.shortcuts import render
from rasp import foo
from choix import views
from choix.forms import ConfigurationForm
from django import forms
from choix.models import Configuration
import json
class ConfigurationFrorm(forms.ModelForm):
class Meta:
model = Configuration
def index(request,self):
cleaned_data = super(ConfigurationForm, self).clean()
temps = cleaned_data.get("temps")
return render(request, 'index.html', {'t' : foo(), 'form':form, 'f':temps})
项目/邮件/视图.py你知道吗
from django.core.mail import send_mail, BadHeaderError
from django.http import HttpResponse, HttpResponseRedirect
from choix import views
from choix.forms import ConfigurationForm
from django import forms
from choix.models import Configuration
class ConfigurationFrorm(forms.ModelForm):
class Meta:
model = Configuration
def index(request,self):
subject = request.POST.get('subject', 'subject')
message = request.POST.get('message', 'attention ! la temperature a depasse le maximum ')
from_email = request.POST.get('from_email', 'jkhgyfydfth@gmail.com')
cleaned_data = super(ConfigurationForm, self).clean()
to = cleaned_data.get("email")
if subject and message and from_email:
try:
send_mail(subject, message, from_email, [ to ])
return HttpResponse('templates/mail.html')
except BadHeaderError:
return HttpResponse('Invalid header found.')
return HttpResponseRedirect('mail')
else:
return HttpResponse('Make sure all fields are entered and valid.')
正如错误消息所说,从django1.8开始,您需要使用
fields
或exclude
类属性显式地告诉ConfigurationForm
要包含哪些模型字段。如果需要所有字段,只需说fields = '__all__'
。Django不再自动地假设这一点。你知道吗您发布的代码中有几个缩进和拼写错误,这使您很难理解。避免这种情况的最好方法是复制并粘贴实际代码,而不是输入代码。你知道吗
相关问题 更多 >
编程相关推荐