简体   繁体   English

使用Python为Google App Engine生成CRUD网页的最快方法是什么?

[英]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. 我使用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. 如果这是一个.NET应用程序,我会使用Visual Studio附带的一个漂亮的控件来快速连接到数据库并将网格绑定到它。 Then go to town adding data. 然后去城镇添加数据。

What's the matching way to do this in Python using Google App Engine? 使用Google App Engine在Python中执行此操作的匹配方式是什么?

In ASP.NET MVC, they have this new "scaffolding" stuff (part of Entity Framework) that will generate CRUD pages for you. 在ASP.NET MVC中,他们有这个新的“脚手架”东西(实体框架的一部分),它将为您生成CRUD页面。 Is there anything like that given a bunch of Model objects in GAE? 在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. PS使用方便的dandy命令行选项--use_sqlite和--datastore_path,一旦我这样做,我就可以在我的开发环境中快速备份我的数据库。

If you are using Django on GAE then you can use the Django Administration site : 如果您在GAE上使用Django,那么您可以使用Django管理站点

So what's Django's approach to these boring, repetitive tasks? 那么Django对这些无聊,重复性任务的处理方法是什么? 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. 使用Django,构建管理界面是一个已解决的问题。

It automatically builds CRUD based HTML forms for managing the model. 它自动构建基于CRUD的HTML表单来管理模型。

Have a look to the appengine admin project. 看看appengine管理项目。

Appengine Admin is simple python package that you can use for creating automatic admin interface for your Google Appengine application. Appengine Admin是一个简单的python包,可用于为您的Google Appengine应用程序创建自动管理界面。

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: 我仍然是一个python和GAE新手,但我在过去的几个月里一直在使用它,所以你可能会发现这有效:

You can use Model.properties() to get the list of properties for the model in question and save it to a list. 您可以使用Model.properties()获取相关模型的属性列表,并将其保存到列表中。 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. 然后,您可以回发到同一页面,您可以使用Request.arguments()将对象属性与模型配对以保存到数据存储区。

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. 据我所知,没有比这更优雅的解决方案,至少不能与你所谈论的ASP.NET MVC脚手架相比。

(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/ Django在App Engine上的问题是你无法使用GAE数据存储区和ndb模型(因此Django管理员不可用),或者你必须开始使用被黑客攻击的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. 很可能对于大多数应用程序而言,最好还是使用Cloud SQL,这基本上是MySQL,所以Django没有问题。

If you need to use the GAE datastore try this framework, which provides a CRUD admin: 如果您需要使用GAE数据存储区,请尝试使用此框架,该框架提供CRUD管理员:
http://ferris-framework.appspot.com/docs/index.html http://ferris-framework.appspot.com/docs/index.html

You can check out Ferris Framework which is tightly integrated to Google App engine and datastore. 您可以查看与Google App引擎和数据存储紧密集成的Ferris Framework

Ferris Framework also has the scaffolding component for creating CRUD actions in a breeze. Ferris Framework还具有用于轻松创建CRUD操作的脚手架组件。 http://ferris-framework.appspot.com/docs/users_guide/scaffolding.html?highlight=scaffolding http://ferris-framework.appspot.com/docs/users_guide/scaffolding.html?highlight=scaffolding

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Python中生成图像缩略图的最快方法是什么? - What is the fastest way to generate image thumbnails in Python? 在Google App Engine中使用python进行文本预测的建议解决方案是什么? - What are suggested solutions for text prediction using python in Google App Engine? 使用python的google app引擎 - google app engine using python 使用 Matplotlib 生成数百万个 png 文件的最快方法是什么? - What's the fastest way to generate millions of png files using Matplotlib? 使用App Engine使用Python生成随机网址 - Generate a random URL with Python using App Engine 此重定向有什么问题? (Google App Engine-Python) - What is wrong with this redirect? (Google App Engine - Python) 什么是通过python将数据推送到Google SpreadSheet的最快方法 - What is the fastest way to push data to a google SpreadSheet via python 在python中为google app引擎网站创建系统属性集合的最佳方法是什么? - What is the best way to create a collection of system properties for a google app engine website in python? 在Python Google App Engine上使用SignedJwtAssertionCredentials - Using SignedJwtAssertionCredentials on Python Google App Engine 使用Python和Google App Engine的Cookie - Cookies using Python and Google App Engine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM