简体   繁体   中英

What is the fastest way to generate CRUD webpages for Google App Engine using Python?

I have created a set of Models for my database using Python. Now I'd like to rapidly load them with some data -- manually. If this were a .NET app, I'd use one of the nifty controls that come with Visual Studio to rapidly connect to the database and bind a grid to it. Then go to town adding data.

What's the matching way to do this in Python using Google App Engine?

In ASP.NET MVC, they have this new "scaffolding" stuff (part of Entity Framework) that will generate CRUD pages for you. Is there anything like that given a bunch of Model objects in GAE?

PS using the handy, dandy command line options --use_sqlite and --datastore_path, I can quickly backup my database in my dev environment once I do this.

If you are using Django on GAE then you can use the Django Administration site :

So what's Django's approach to these boring, repetitive tasks? It does it all for you—in just a couple of lines of code, no less. With Django, building an admin interface is a solved problem.

It automatically builds CRUD based HTML forms for managing the model.

Have a look to the appengine admin project.

Appengine Admin is simple python package that you can use for creating automatic admin interface for your Google Appengine application.

Here is a screenshot:

在此输入图像描述

and here is the quickstart tutorial.

After creating your models, simply adding this line of code:

# Register to admin site
appengine_admin.register(..your list of class Models definition)

and after have defined the proper route to the admin with:

(r'^(/admin)(.*)$', appengine_admin.Admin)

you can access to the customized admin that offers the following features:

  • List records for each registered model
  • Create new records
  • Update/edit records
  • Delete records

I'm still something of a python and GAE newbie, but I've been working with it a lot over the past few months so you might find that this works:

You can use Model.properties() to get the list of properties for the model in question and save it to a list. You can then add the list to the context dictionary for use in your template. In your template iterate over the loop to generate a basic list of input fields with the names matching each property.

{% for tItem in list %}
    <input type="text" name="{{ tItem }}" />
{% endfor %}

Then you can post back to the same page, where you can use Request.arguments() to pair your object properties to your model for saving into the datastore.

To my knowledge there's not a much more elegant solution than that, at least not comparable to the ASP.NET MVC scaffolding that you're talking about.

(disclaimer: I've not actually tried this so there is likely a problem or two that needs to be sorted)

The trouble with Django on App Engine is you can't use the GAE datastore and ndb models (so the Django admin is not available), or you have to start using a hacked version of Django: http://django-nonrel.org/

Well probably for most apps you're better off using Cloud SQL anyway, which is basically MySQL so no prob with Django.

If you need to use the GAE datastore try this framework, which provides a CRUD admin:
http://ferris-framework.appspot.com/docs/index.html

You can check out Ferris Framework which is tightly integrated to Google App engine and datastore.

Ferris Framework also has the scaffolding component for creating CRUD actions in a breeze. http://ferris-framework.appspot.com/docs/users_guide/scaffolding.html?highlight=scaffolding

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM