Guest User

Untitled

a guest
Jun 18th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. import web
  2. from web import form
  3.  
  4. urls = (
  5. '/', 'index',
  6. '/contact', 'contact',
  7. )
  8.  
  9. app = web.application(urls, globals())
  10.  
  11. db = web.database(dbn='mysql', user='username', pw='password', db='dbname')
  12. render = web.template.render('templates/')
  13.  
  14. contactForm = form.Form(
  15. form.Textbox('name',
  16. form.notnull,
  17. description = 'Your Name'
  18. ),
  19. form.Textbox('email',
  20. form.notnull,
  21. description = 'Your Email'
  22. ),
  23. form.Textbox('subject',
  24. form.notnull,
  25. description = 'Subject',
  26. value = 'I\'m going to buy you something'
  27. ),
  28. form.Textarea('message',
  29. form.notnull,
  30. description = 'Message'
  31. )
  32. )
  33.  
  34. class index:
  35. def GET(self):
  36. contactform = contactForm()
  37. return render.index(contactform)
  38.  
  39. class contact:
  40. def POST(self):
  41. contactform = contactForm()
  42. if not contactform.validates():
  43. return render.index(contactform)
  44. else:
  45. i = web.input()
  46. PostageApp('apikey').send_message('youremailaddr', i.email, i.subject, { 'text/plain': i.message })
  47. raise web.seeother('/')
  48.  
  49.  
  50.  
  51. if __name__ == "__main__":
  52. app.run()
Add Comment
Please, Sign In to add comment