Tutorial about making forms in AppEngine with Python. First part.
Basic Form Tutorial Google AppEngine
- AppEngine Forms in Python
- Submit AppEngine Forms Using POST in Python
- AppEngine Edit Form in Python
- Delete Row From Datastore in AppEngine
Here you learn how to make forms for AppEngine in Python.
Make The Model:
First make a model, for forms data and then let django generate from from it. Here I have made model with some random fields.There are many kinds of form fields. As you can see they are called properties. You can find the full list of properties from Googles: Types and Property Classes. As you can see there are also parameters, those are form validation parameters. Full list of those you can find from Googles: The Property Class.Source code viewer
class MyModel(db.Model): title = db.StringProperty(required=True) type = db.StringProperty(choices=['Earth','Dark','Light','Water','Fire','Wind','Divine']) year = db.IntegerProperty() review = db.TextProperty()Programming Language: Python
Make The Form
This code makes the form from the model. This is made by the django library.Source code viewer
class MyForm(djangoforms.ModelForm): class Meta: model = MyModelProgramming Language: Python
Our AppEngine Form in Python
Lets print our form to the screen. The complete code:Source code viewer
import os from google.appengine.ext import webapp, db from google.appengine.ext.webapp.util import run_wsgi_app from google.appengine.ext.db import djangoforms # Here goes the model. # Here goes the form. class MainPage(webapp.RequestHandler): def get(self): self.response.out.write('<html><body>' '<form method="POST" action="/">' '<table>') self.response.out.write(MyForm()) #generates form self.response.out.write('</table>' '<input type="submit">' '</form></body></html>') application = webapp.WSGIApplication( [('/', MainPage)], debug=True) def main(): run_wsgi_app(application) if __name__ == "__main__": main()Programming Language: Python
Now that the "AppEngine Forms in Python" tutorial is complete you can check out the second part: Submit AppEngine Forms Using POST in Python.