- 浏览: 2490895 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
google(二)python使用和发布到google
我在google申请了帐号,呵呵,想试试在那里发布我新写的简单python应用。
首先学习google的python入门文档:
http://code.google.com/intl/zh-CN/appengine/docs/python/gettingstarted/
5 使用数据存储区
按照文档上的,修改了helloworld.py,保存问候信息和用户信息到数据存储区域:
import cgi
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
class Greeting(db.Model):
author = db.UserProperty()
content = db.StringProperty(multiline=True)
date = db.DateTimeProperty(auto_now_add=True)
class MainPage(webapp.RequestHandler):
def get(self):
self.response.out.write('<html><body>')
#greetings = db.GqlQuery("SELECT * FROM Greeting ORDER BY date DESC LIMIT 10")
#两种写法都可以,下面一种是简写
greetings = Greeting.gql("ORDER BY date DESC LIMIT 10")
for greeting in greetings:
if greeting.author:
self.response.out.write('<b>%s</b> wrote:' % greeting.author.nickname())
else:
self.response.out.write('An anonymous person wrote:')
self.response.out.write('<blockquote>%s</blockquote>' %
cgi.escape(greeting.content))
# Write the submission form and the footer of the page
self.response.out.write("""
<form action="/sign" method="post">
<div><textarea name="content" rows="3" cols="60"></textarea></div>
<div><input type="submit" value="Sign Guestbook"></div>
</form>
</body>
</html>""")
class Guestbook(webapp.RequestHandler):
def post(self):
greeting = Greeting()
if users.get_current_user():
greeting.author = users.get_current_user()
greeting.content = self.request.get('content')
greeting.put()
self.redirect('/')
application = webapp.WSGIApplication(
[('/', MainPage),
('/sign', Guestbook)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
启动服务google_appengine/dev_appserver.py /home/sillycat/work/easyappenginepython/
访问http://localhost:8080就可以看到效果了。录入了几个信息后,后被记录并列表出来了。
清除数据并启动服务:
google_appengine/dev_appserver.py --clear_datastore /home/sillycat/work/easyappenginepython/
数据存储区详细文档:
http://code.google.com/intl/zh-CN/appengine/docs/python/datastore/
另外文档上介绍了几个写GQL过滤的方法:
使用位置参数:
if users.get_current_user():
greetings = Greeting.gql("WHERE author = :1 ORDER BY date DESC",
users.get_current_user())
使用命名参数:
greetings = Greeting.gql("WHERE author = :author ORDER BY date DESC",
author=users.get_current_user())
用API filter来查询:
greetings = Greeting.all()
greetings.filter("author =", users.get_current_user())
greetings.order("-date")
6.使用模板
嘿嘿,google使用了类似于django的模板,修改helloworld.py文件如下:
import cgi
import os
from google.appengine.ext.webapp import template
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
class Greeting(db.Model):
author = db.UserProperty()
content = db.StringProperty(multiline=True)
date = db.DateTimeProperty(auto_now_add=True)
class MainPage(webapp.RequestHandler):
def get(self):
greetings_query = Greeting.all().order('-date')
greetings = greetings_query.fetch(10)
if users.get_current_user():
url = users.create_logout_url(self.request.uri)
url_linktext = 'Logout'
else:
url = users.create_login_url(self.request.uri)
url_linktext = 'Login'
template_values = {
'greetings': greetings,
'url': url,
'url_linktext': url_linktext,
}
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
class Guestbook(webapp.RequestHandler):
def post(self):
greeting = Greeting()
if users.get_current_user():
greeting.author = users.get_current_user()
greeting.content = self.request.get('content')
greeting.put()
self.redirect('/')
application = webapp.WSGIApplication(
[('/', MainPage),
('/sign', Guestbook)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
在helloworld目录增加文件/helloworld/index.html如下:
<html>
<body>
{% for greeting in greetings %}
{% if greeting.author %}
<b>{{ greeting.author.nickname }}</b> wrote:
{% else %}
An anonymous person wrote:
{% endif %}
<blockquote>{{ greeting.content|escape }}</blockquote>
{% endfor %}
<form action="/sign" method="post">
<div><textarea name="content" rows="3" cols="60"></textarea></div>
<div><input type="submit" value="Sign Guestbook"></div>
</form>
<a href="{{ url }}">{{ url_linktext }}</a>
</body>
</html>
django模板引擎详细文档:
http://www.djangoproject.com/documentation/0.96/templates/
7.使用静态文件
修改配置文件app.yaml:
handlers:
- url: /stylesheets
static_dir: stylesheets
- url: /.*
script: helloworld/helloworld.py
在工程中新建目录stylesheets
新建文件/stylesheets/main.css,内容如下:
body {
font-family: Verdana, Helvetica, sans-serif;
background-color: #DDDDDD;
}
再在文件/helloworld/index.html加上这个CSS的应用:
<head>
<link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
</head>
ok,访问http://localhost:8080就能看到加了背景色的效果了。
app.yaml文件配置参考:
http://code.google.com/intl/zh-CN/appengine/docs/python/config/appconfig.html
8.上传应用
访问主页:
https://appengine.google.com/
我在上面注册了帐号,新增了一个app
sillycatkiko
我的sillycat,luohuazju貌似都有了,所以就只能用这个了。
修改项目的app.yaml文件如下:
application: sillycatkiko
version: 1
runtime: python
api_version: 1
handlers:
- url: /stylesheets
static_dir: stylesheets
- url: /.*
script: helloworld/helloworld.py
使用命令行发布:
sillycat@sillycat-desktop:~/tools$ google_appengine/appcfg.py update /home/sillycat/work/easyappenginepython/
中途让我输入了用户名和密码。
访问地址:
http://sillycatkiko.appspot.com/
就能看到我刚才上传的应用了。简单的文档实验完毕。继续可以看看GOOGLE的其他文档和别人的应用。
我在google申请了帐号,呵呵,想试试在那里发布我新写的简单python应用。
首先学习google的python入门文档:
http://code.google.com/intl/zh-CN/appengine/docs/python/gettingstarted/
5 使用数据存储区
按照文档上的,修改了helloworld.py,保存问候信息和用户信息到数据存储区域:
import cgi
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
class Greeting(db.Model):
author = db.UserProperty()
content = db.StringProperty(multiline=True)
date = db.DateTimeProperty(auto_now_add=True)
class MainPage(webapp.RequestHandler):
def get(self):
self.response.out.write('<html><body>')
#greetings = db.GqlQuery("SELECT * FROM Greeting ORDER BY date DESC LIMIT 10")
#两种写法都可以,下面一种是简写
greetings = Greeting.gql("ORDER BY date DESC LIMIT 10")
for greeting in greetings:
if greeting.author:
self.response.out.write('<b>%s</b> wrote:' % greeting.author.nickname())
else:
self.response.out.write('An anonymous person wrote:')
self.response.out.write('<blockquote>%s</blockquote>' %
cgi.escape(greeting.content))
# Write the submission form and the footer of the page
self.response.out.write("""
<form action="/sign" method="post">
<div><textarea name="content" rows="3" cols="60"></textarea></div>
<div><input type="submit" value="Sign Guestbook"></div>
</form>
</body>
</html>""")
class Guestbook(webapp.RequestHandler):
def post(self):
greeting = Greeting()
if users.get_current_user():
greeting.author = users.get_current_user()
greeting.content = self.request.get('content')
greeting.put()
self.redirect('/')
application = webapp.WSGIApplication(
[('/', MainPage),
('/sign', Guestbook)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
启动服务google_appengine/dev_appserver.py /home/sillycat/work/easyappenginepython/
访问http://localhost:8080就可以看到效果了。录入了几个信息后,后被记录并列表出来了。
清除数据并启动服务:
google_appengine/dev_appserver.py --clear_datastore /home/sillycat/work/easyappenginepython/
数据存储区详细文档:
http://code.google.com/intl/zh-CN/appengine/docs/python/datastore/
另外文档上介绍了几个写GQL过滤的方法:
使用位置参数:
if users.get_current_user():
greetings = Greeting.gql("WHERE author = :1 ORDER BY date DESC",
users.get_current_user())
使用命名参数:
greetings = Greeting.gql("WHERE author = :author ORDER BY date DESC",
author=users.get_current_user())
用API filter来查询:
greetings = Greeting.all()
greetings.filter("author =", users.get_current_user())
greetings.order("-date")
6.使用模板
嘿嘿,google使用了类似于django的模板,修改helloworld.py文件如下:
import cgi
import os
from google.appengine.ext.webapp import template
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
class Greeting(db.Model):
author = db.UserProperty()
content = db.StringProperty(multiline=True)
date = db.DateTimeProperty(auto_now_add=True)
class MainPage(webapp.RequestHandler):
def get(self):
greetings_query = Greeting.all().order('-date')
greetings = greetings_query.fetch(10)
if users.get_current_user():
url = users.create_logout_url(self.request.uri)
url_linktext = 'Logout'
else:
url = users.create_login_url(self.request.uri)
url_linktext = 'Login'
template_values = {
'greetings': greetings,
'url': url,
'url_linktext': url_linktext,
}
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
class Guestbook(webapp.RequestHandler):
def post(self):
greeting = Greeting()
if users.get_current_user():
greeting.author = users.get_current_user()
greeting.content = self.request.get('content')
greeting.put()
self.redirect('/')
application = webapp.WSGIApplication(
[('/', MainPage),
('/sign', Guestbook)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
在helloworld目录增加文件/helloworld/index.html如下:
<html>
<body>
{% for greeting in greetings %}
{% if greeting.author %}
<b>{{ greeting.author.nickname }}</b> wrote:
{% else %}
An anonymous person wrote:
{% endif %}
<blockquote>{{ greeting.content|escape }}</blockquote>
{% endfor %}
<form action="/sign" method="post">
<div><textarea name="content" rows="3" cols="60"></textarea></div>
<div><input type="submit" value="Sign Guestbook"></div>
</form>
<a href="{{ url }}">{{ url_linktext }}</a>
</body>
</html>
django模板引擎详细文档:
http://www.djangoproject.com/documentation/0.96/templates/
7.使用静态文件
修改配置文件app.yaml:
handlers:
- url: /stylesheets
static_dir: stylesheets
- url: /.*
script: helloworld/helloworld.py
在工程中新建目录stylesheets
新建文件/stylesheets/main.css,内容如下:
body {
font-family: Verdana, Helvetica, sans-serif;
background-color: #DDDDDD;
}
再在文件/helloworld/index.html加上这个CSS的应用:
<head>
<link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
</head>
ok,访问http://localhost:8080就能看到加了背景色的效果了。
app.yaml文件配置参考:
http://code.google.com/intl/zh-CN/appengine/docs/python/config/appconfig.html
8.上传应用
访问主页:
https://appengine.google.com/
我在上面注册了帐号,新增了一个app
sillycatkiko
我的sillycat,luohuazju貌似都有了,所以就只能用这个了。
修改项目的app.yaml文件如下:
application: sillycatkiko
version: 1
runtime: python
api_version: 1
handlers:
- url: /stylesheets
static_dir: stylesheets
- url: /.*
script: helloworld/helloworld.py
使用命令行发布:
sillycat@sillycat-desktop:~/tools$ google_appengine/appcfg.py update /home/sillycat/work/easyappenginepython/
中途让我输入了用户名和密码。
访问地址:
http://sillycatkiko.appspot.com/
就能看到我刚才上传的应用了。简单的文档实验完毕。继续可以看看GOOGLE的其他文档和别人的应用。
发表评论
-
NodeJS12 and Zlib
2020-04-01 07:44 434NodeJS12 and Zlib It works as ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 297Traefik 2020(1)Introduction and ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 379Private Registry 2020(1)No auth ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 339Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 421NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 367Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 295Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 214GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 396GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 281GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 269Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 268Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 255Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 241Serverless with NodeJS and Tenc ... -
NodeJS MySQL Library and npmjs
2020-02-07 06:21 240NodeJS MySQL Library and npmjs ... -
Python Library 2019(1)requests and aiohttp
2019-12-18 01:12 229Python Library 2019(1)requests ... -
NodeJS Installation 2019
2019-10-20 02:57 524NodeJS Installation 2019 Insta ... -
Monitor Tool 2019(2)Monit on Multiple Instances and Email Alerts
2019-10-18 10:57 232Monitor Tool 2019(2)Monit on Mu ... -
Sqlite Database 2019(1)Sqlite3 Installation and Docker phpsqliteadmin
2019-09-05 11:24 324Sqlite Database 2019(1)Sqlite3 ... -
Supervisor 2019(2)Ubuntu and Multiple Services
2019-08-19 10:53 323Supervisor 2019(2)Ubuntu and Mu ...
相关推荐
Google Python 规范,网上能够找到的最好的中文版本,带书签.翻译资料也很好.可以用来作为公司 python 规范的模板.希望能够帮到大家
Python编码规范(Google),Python编码规范(Google),Python编码规范(Google),Python编码规范(Google),Python编码规范(Google)
python下载谷歌卫星有标签的瓦片地图
基于Python的离线Google地图操作实现.pdf
使用 Python 构建一个简单的 ChatBot,它使用 Google 搜索作为其大脑。该应用程序由 Python 3 服务器和 Web 界面组成
google的python练习,google的python练习,google的python练习
google的python编码规范.pdf
网上找到的Goolge Python编码规范。包含两个版本,Google Python Style Guide中文版_li3p.pdf,Google-python-style-guide中文版_guoqiao.pdf。两份文档内容基本一致,guoqiao翻译的格式比较好,带详细书签。
网上收集的Goolge Python编码规范。包含两个版本,Google Python Style Guide中文版_li3p.pdf,Google-python-style-guide中文版_guoqiao.pdf。两份文档内容基本一致,guoqiao翻译的格式比较好,而且带详细书签。
google python风格指南,http://zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_style_rules/
python实现调用google,里面包含js代码段,python代码段,建议用第三方开发工具pycharm;里面有第三方依赖包,使用前请先pip安装所依赖的安装包,调用入口function.py,直接运行function.py即可
调用python接口使用googlenet进行图像识别,代码可以改了路径直接用~~~~~~~~~~~~
google的python编码规范
google python 教学 课程,odt 类型文件LibreOffice可以打开(开源免费的office软件,windows上也可以安装),微软的office没有试过能不能打开。
mirror-quickstart-python, 面向 python的Google镜像快速入门 Google镜像快速入门 api快速入门的文档在 developers.google.com. 上维护有关更多信息,请参见这里: ...
使用ptyon调用google drive api上传文件,python版本64bit 2.7.4
学习使用谷歌Tensorflow示例
Linux 安装Google SDK时要求安装Python 2.7或以上版本
python的小程序,安装selenium后,调用谷歌浏览器打开百度,搜索相应内容
google 的 python 和 c++ 代码规范 项目中,为了避免混杂的,代码风格, 代码规范就派上用场了!