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 FormThis 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 PythonLets 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):
- '<form method="POST" action="/">'
- self.response.out.write(MyForm()) #generates form
- '<input type="submit">'
- application = webapp.WSGIApplication(
- [('/', MainPage)],
- def main():
- 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.