Skip to content

Instantly share code, notes, and snippets.

@geoffa
Forked from trey/forms.py
Created December 2, 2009 22:36
Show Gist options
  • Save geoffa/247675 to your computer and use it in GitHub Desktop.
Save geoffa/247675 to your computer and use it in GitHub Desktop.
from django import forms
from myapp.models import Mymodel
class MyForm(forms.ModelForm):
class Meta:
model=Mymodel
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from myapp.forms import MyForm
def my_view(request):
"""
Documentation for my view.
"""
if request.POST:
form = MyForm(data=request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/')
# else:
# Errors and validation message taken care of for you. Neat.
else:
form = MyForm()
return render_to_response('my_template.html', {'form': form})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment