From 6d140a50c835a7008a81cb395fd244d8aa8b6294 Mon Sep 17 00:00:00 2001 From: Kriti Godey Date: Fri, 26 Feb 2010 16:12:50 -0500 Subject: [PATCH] Added a view for a form to add a sandwich, made a url for it and made a templates folder with a template for the sandwich-adding. --- templates/sandwich.html | 11 +++++++++++ urls.py | 4 +++- views.py | 21 ++++++++++++--------- 3 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 templates/sandwich.html diff --git a/templates/sandwich.html b/templates/sandwich.html new file mode 100644 index 0000000..3ae0f3e --- /dev/null +++ b/templates/sandwich.html @@ -0,0 +1,11 @@ + + + Add a sandwich! + +

Add a new sandwich

+
+ {{ form.as_p }} + +
+ + \ No newline at end of file diff --git a/urls.py b/urls.py index be8af48..82f72f0 100644 --- a/urls.py +++ b/urls.py @@ -1,5 +1,7 @@ from django.conf.urls.defaults import * +import views +from django.shortcuts import render_to_response urlpatterns = patterns('', - (r'^addsandwich/$', 'views.add_sandwich'), + (r'^addsandwich/$', views.add_sandwich), ) diff --git a/views.py b/views.py index a56e4ec..f9c5cd3 100644 --- a/views.py +++ b/views.py @@ -1,14 +1,17 @@ from django.http import HttpResponse from forms import SandwichForm, IngredientForm, ArtistForm +from django.shortcuts import render_to_response def add_sandwich(request): - sform = SandwichForm() - - -def add_artist(request): - aform = ArtistForm() - - -def add_ingredient(request): - iform = IngredientForm() \ No newline at end of file + if request.method == 'POST': # If the form has been submitted... + form = SandwichForm(request.POST) # A form bound to the POST data + if form.is_valid(): # All validation rules pass + # Process the data in form.cleaned_data + # ... + thankshtml = "

Thanks! Your sandwich has been added!

" + return HttpResponse(thankshtml) # Redirect after POST + else: + form = SandwichForm() # An unbound form + + return render_to_response('sandwich.html', {'form': form,}) \ No newline at end of file -- 2.20.1