Created
October 19, 2010 01:57
-
-
Save drewtempelmeyer/633468 to your computer and use it in GitHub Desktop.
Barebones wedding site in web.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import web | |
from web import form | |
urls = ( | |
'/', 'index', | |
'/contact', 'contact', | |
) | |
app = web.application(urls, globals()) | |
db = web.database(dbn='mysql', user='username', pw='password', db='dbname') | |
render = web.template.render('templates/') | |
contactForm = form.Form( | |
form.Textbox('name', | |
form.notnull, | |
description = 'Your Name' | |
), | |
form.Textbox('email', | |
form.notnull, | |
description = 'Your Email' | |
), | |
form.Textbox('subject', | |
form.notnull, | |
description = 'Subject', | |
value = 'I\'m going to buy you something' | |
), | |
form.Textarea('message', | |
form.notnull, | |
description = 'Message' | |
) | |
) | |
class index: | |
def GET(self): | |
contactform = contactForm() | |
return render.index(contactform) | |
class contact: | |
def POST(self): | |
contactform = contactForm() | |
if not contactform.validates(): | |
return render.index(contactform) | |
else: | |
i = web.input() | |
PostageApp('apikey').send_message('youremailaddr', i.email, i.subject, { 'text/plain': i.message }) | |
raise web.seeother('/') | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment