1 from django.http import HttpResponse
2 from forms import SandwichForm, IngredientForm, ArtistForm
3 from django.shortcuts import render_to_response
6 def add_sandwich(request):
7 if request.method == 'POST': # If the form has been submitted...
8 form = SandwichForm(request.POST) # A form bound to the POST data
9 if form.is_valid(): # All validation rules pass
10 # Process the data in form.cleaned_data
12 thankshtml = "<p class=\"formthanks\">Thanks! Your sandwich has been added!</p>"
13 return HttpResponse(thankshtml) # Redirect after POST
15 form = SandwichForm() # An unbound form
17 return render_to_response('sandwich.html', {'form': form,})