- Author:
- henrikv
- Posted:
- February 27, 2007
- Language:
- Python
- Version:
- Pre .96
- Score:
- 6 (after 6 ratings)
A simple way to get started using newforms. Implement a contact form. Mine saves the data in a table and sends a dedicated mailbox the feedback as well. I added support for TinyMCE as described in the django wiki.
http://code.djangoproject.com/wiki/CustomWidgetsTinyMCE?format=txt
Anyway use this as a starting point for writing your own form handling.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | from django import newforms as forms
from django.newforms import widgets
from live.utils.custom_widgets import TinyMCE
from live.about.models import Feedback
class ContactForm(forms.Form):
from_email = forms.EmailField(label='email',initial='[email protected]')
subject = forms.CharField(max_length=100)
message = forms.CharField(widget=TinyMCE())
subject_prefix = forms.CharField(widget=widgets.HiddenInput,initial='feedback')
def save(self,commit = True,user=None):
feedback = Feedback(**self.clean_data)
feedback.user = user
if commit:
feedback.save()
return feedback
def contact(request,template="about/contact.html",redirect_to="/"):
form = None
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
feedback = form.save(user=request.user)
return HttpResponseRedirect("/")
else:
form = ContactForm()
r = render_to_response(template, {'contact_form':form})
return r
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 9 months ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 9 months, 1 week ago
- Serializer factory with Django Rest Framework by julio 1 year, 4 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 4 months ago
- Help text hyperlinks by sa2812 1 year, 5 months ago
Comments
Please login first before commenting.