Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.forms import ModelForm
- from django import forms
- from models import Contacts
- class ContactForm(forms.Form):
- class Meta:
- model = Contacts
- name = forms.CharField(max_length=30)
- email = forms.EmailField(max_length=254)
- message = forms.CharField(
- max_length=2000,
- widget=forms.Textarea(),
- help_text='Write here your message!'
- )
- def clean(self):
- cleaned_data = super(ContactForm, self).clean()
- name = cleaned_data.get('name')
- email = cleaned_data.get('email')
- message = cleaned_data.get('message')
- if not name and not email and not message:
- raise forms.ValidationError('You have to write something!')
- def addcontact(request):
- if request.POST:
- form_c = ContactForm(request.POST)
- if form_c.is_valid():
- f.save() # не работает т.к. у ContactForm нет этого метода
- return HttpResponseRedirect('/contacts/thanks/')
- else:
- form_c = ContactForm()
- return render(request, 'contacts.html', {'form_c': form_c})
Add Comment
Please, Sign In to add comment