Enviar búsqueda
Cargar
GAE Meets Django
•
3 recomendaciones
•
492 vistas
G
guest96a888
Seguir
Tecnología
Noticias y política
Denunciar
Compartir
Denunciar
Compartir
1 de 37
Descargar ahora
Descargar para leer sin conexión
Recomendados
Devoxx : being productive with JHipster
Devoxx : being productive with JHipster
Julien Dubois
Headless CMS. Sitecore JSS getting started, tips and tricks
Headless CMS. Sitecore JSS getting started, tips and tricks
Artsem Prashkovich
How to keep maintainability of long life Scala applications
How to keep maintainability of long life Scala applications
takezoe
Jhipster
Jhipster
Edlaine Zamora
GitBucket: Git Centric Software Development Platform by Scala
GitBucket: Git Centric Software Development Platform by Scala
takezoe
Introduction to Firebase on Android
Introduction to Firebase on Android
amsanjeev
Grails 3.0 Preview
Grails 3.0 Preview
graemerocher
Building a dev pipeline using GitHub Actions, Node.js, and AWS ECS Fargate
Building a dev pipeline using GitHub Actions, Node.js, and AWS ECS Fargate
datree
Recomendados
Devoxx : being productive with JHipster
Devoxx : being productive with JHipster
Julien Dubois
Headless CMS. Sitecore JSS getting started, tips and tricks
Headless CMS. Sitecore JSS getting started, tips and tricks
Artsem Prashkovich
How to keep maintainability of long life Scala applications
How to keep maintainability of long life Scala applications
takezoe
Jhipster
Jhipster
Edlaine Zamora
GitBucket: Git Centric Software Development Platform by Scala
GitBucket: Git Centric Software Development Platform by Scala
takezoe
Introduction to Firebase on Android
Introduction to Firebase on Android
amsanjeev
Grails 3.0 Preview
Grails 3.0 Preview
graemerocher
Building a dev pipeline using GitHub Actions, Node.js, and AWS ECS Fargate
Building a dev pipeline using GitHub Actions, Node.js, and AWS ECS Fargate
datree
Introduction to Grails
Introduction to Grails
Hiten Pratap Singh
JHipster Code 2020 keynote
JHipster Code 2020 keynote
Julien Dubois
StackEngine Demo - Docker Austin
StackEngine Demo - Docker Austin
Boyd Hemphill
Migrating NYSenate.gov
Migrating NYSenate.gov
Pantheon
Introduction, Examples - Firebase
Introduction, Examples - Firebase
Eueung Mulyana
Google Cloud Platform - for Mobile Solutions
Google Cloud Platform - for Mobile Solutions
Simon Su
Image archive, analysis & report generation with Google Cloud
Image archive, analysis & report generation with Google Cloud
wesley chun
JHipster overview and roadmap (August 2017)
JHipster overview and roadmap (August 2017)
Julien Dubois
Django framework
Django framework
ShantanuMane5
Java in azure dev ops
Java in azure dev ops
Jeffray Huang
A High-Performance Solution to Microservice UI Composition @ XConf Hamburg
A High-Performance Solution to Microservice UI Composition @ XConf Hamburg
Dr. Arif Wider
OpenStack Ansible for private cloud at Kaidee
OpenStack Ansible for private cloud at Kaidee
Jirayut Nimsaeng
Why BaaS is crucial to early stage startups
Why BaaS is crucial to early stage startups
Jane Chung
GLobal Azure Bootcamp 2016 Lyon Benjamin Talmard Azure Micro-services Contain...
GLobal Azure Bootcamp 2016 Lyon Benjamin Talmard Azure Micro-services Contain...
AZUG FR
Gr8Conf 2016 - GORM Inside and Out
Gr8Conf 2016 - GORM Inside and Out
graemerocher
ng4 webpack and yarn in JHipster
ng4 webpack and yarn in JHipster
Sendil Kumar
Gradle enabled android project
Gradle enabled android project
Shaka Huang
Mastering Grails 3 Plugins - GR8Conf US 2016
Mastering Grails 3 Plugins - GR8Conf US 2016
Alvaro Sanchez-Mariscal
Gradle build automation tool
Gradle build automation tool
Ioan Eugen Stan
How we leveraged Drupal to build a leading SaaS product
How we leveraged Drupal to build a leading SaaS product
Invotra
Experiment PSY General Knowledge
Experiment PSY General Knowledge
jimxyz
24hrsCamp @SketchIn
24hrsCamp @SketchIn
24hrsCamp
Más contenido relacionado
La actualidad más candente
Introduction to Grails
Introduction to Grails
Hiten Pratap Singh
JHipster Code 2020 keynote
JHipster Code 2020 keynote
Julien Dubois
StackEngine Demo - Docker Austin
StackEngine Demo - Docker Austin
Boyd Hemphill
Migrating NYSenate.gov
Migrating NYSenate.gov
Pantheon
Introduction, Examples - Firebase
Introduction, Examples - Firebase
Eueung Mulyana
Google Cloud Platform - for Mobile Solutions
Google Cloud Platform - for Mobile Solutions
Simon Su
Image archive, analysis & report generation with Google Cloud
Image archive, analysis & report generation with Google Cloud
wesley chun
JHipster overview and roadmap (August 2017)
JHipster overview and roadmap (August 2017)
Julien Dubois
Django framework
Django framework
ShantanuMane5
Java in azure dev ops
Java in azure dev ops
Jeffray Huang
A High-Performance Solution to Microservice UI Composition @ XConf Hamburg
A High-Performance Solution to Microservice UI Composition @ XConf Hamburg
Dr. Arif Wider
OpenStack Ansible for private cloud at Kaidee
OpenStack Ansible for private cloud at Kaidee
Jirayut Nimsaeng
Why BaaS is crucial to early stage startups
Why BaaS is crucial to early stage startups
Jane Chung
GLobal Azure Bootcamp 2016 Lyon Benjamin Talmard Azure Micro-services Contain...
GLobal Azure Bootcamp 2016 Lyon Benjamin Talmard Azure Micro-services Contain...
AZUG FR
Gr8Conf 2016 - GORM Inside and Out
Gr8Conf 2016 - GORM Inside and Out
graemerocher
ng4 webpack and yarn in JHipster
ng4 webpack and yarn in JHipster
Sendil Kumar
Gradle enabled android project
Gradle enabled android project
Shaka Huang
Mastering Grails 3 Plugins - GR8Conf US 2016
Mastering Grails 3 Plugins - GR8Conf US 2016
Alvaro Sanchez-Mariscal
Gradle build automation tool
Gradle build automation tool
Ioan Eugen Stan
How we leveraged Drupal to build a leading SaaS product
How we leveraged Drupal to build a leading SaaS product
Invotra
La actualidad más candente
(20)
Introduction to Grails
Introduction to Grails
JHipster Code 2020 keynote
JHipster Code 2020 keynote
StackEngine Demo - Docker Austin
StackEngine Demo - Docker Austin
Migrating NYSenate.gov
Migrating NYSenate.gov
Introduction, Examples - Firebase
Introduction, Examples - Firebase
Google Cloud Platform - for Mobile Solutions
Google Cloud Platform - for Mobile Solutions
Image archive, analysis & report generation with Google Cloud
Image archive, analysis & report generation with Google Cloud
JHipster overview and roadmap (August 2017)
JHipster overview and roadmap (August 2017)
Django framework
Django framework
Java in azure dev ops
Java in azure dev ops
A High-Performance Solution to Microservice UI Composition @ XConf Hamburg
A High-Performance Solution to Microservice UI Composition @ XConf Hamburg
OpenStack Ansible for private cloud at Kaidee
OpenStack Ansible for private cloud at Kaidee
Why BaaS is crucial to early stage startups
Why BaaS is crucial to early stage startups
GLobal Azure Bootcamp 2016 Lyon Benjamin Talmard Azure Micro-services Contain...
GLobal Azure Bootcamp 2016 Lyon Benjamin Talmard Azure Micro-services Contain...
Gr8Conf 2016 - GORM Inside and Out
Gr8Conf 2016 - GORM Inside and Out
ng4 webpack and yarn in JHipster
ng4 webpack and yarn in JHipster
Gradle enabled android project
Gradle enabled android project
Mastering Grails 3 Plugins - GR8Conf US 2016
Mastering Grails 3 Plugins - GR8Conf US 2016
Gradle build automation tool
Gradle build automation tool
How we leveraged Drupal to build a leading SaaS product
How we leveraged Drupal to build a leading SaaS product
Destacado
Experiment PSY General Knowledge
Experiment PSY General Knowledge
jimxyz
24hrsCamp @SketchIn
24hrsCamp @SketchIn
24hrsCamp
Glucocorticoides
Glucocorticoides
medicinaudm
Los 5 Secretos De Un Amujer Feliz
Los 5 Secretos De Un Amujer Feliz
Caro Lina
Marcas
Marcas
Heriditafanzine
Ramrod Taff
Ramrod Taff
Sphelios
Quality Toolkit Rsc Nw
Quality Toolkit Rsc Nw
Andrew Eynon
Ciencias Antropológicas
Ciencias Antropológicas
Joselinne_0985
Za Teb
Za Teb
Slavina Velkova
EL MILAGRO DE LA VIDA
EL MILAGRO DE LA VIDA
montanicelia
Test 22
Test 22
guest5bdb77
PresentacióN1
PresentacióN1
guest5ab9fe
Paradise On Earth
Paradise On Earth
Shaikhani.
Aula 01
Aula 01
rpadovani
011 Lamonjayelhippie
011 Lamonjayelhippie
Iago Fernández
Web技術勉強会5回目(Slide Share用)
Web技術勉強会5回目(Slide Share用)
龍一 田中
FHS Reunion 1
FHS Reunion 1
fruitlandclassof98
Iris Alvial
Iris Alvial
guest94c61d
Rivera Egaf4
Rivera Egaf4
Rodrigo Pascual
Szukajmy spichlerza
Szukajmy spichlerza
natan
Destacado
(20)
Experiment PSY General Knowledge
Experiment PSY General Knowledge
24hrsCamp @SketchIn
24hrsCamp @SketchIn
Glucocorticoides
Glucocorticoides
Los 5 Secretos De Un Amujer Feliz
Los 5 Secretos De Un Amujer Feliz
Marcas
Marcas
Ramrod Taff
Ramrod Taff
Quality Toolkit Rsc Nw
Quality Toolkit Rsc Nw
Ciencias Antropológicas
Ciencias Antropológicas
Za Teb
Za Teb
EL MILAGRO DE LA VIDA
EL MILAGRO DE LA VIDA
Test 22
Test 22
PresentacióN1
PresentacióN1
Paradise On Earth
Paradise On Earth
Aula 01
Aula 01
011 Lamonjayelhippie
011 Lamonjayelhippie
Web技術勉強会5回目(Slide Share用)
Web技術勉強会5回目(Slide Share用)
FHS Reunion 1
FHS Reunion 1
Iris Alvial
Iris Alvial
Rivera Egaf4
Rivera Egaf4
Szukajmy spichlerza
Szukajmy spichlerza
Similar a GAE Meets Django
Groovy & Grails - From Scratch to Production
Groovy & Grails - From Scratch to Production
Tal Maayani
Google App Engine
Google App Engine
Hung-yu Lin
Google cloud platform Introduction - 2014
Google cloud platform Introduction - 2014
Simon Su
CloudOps evening presentation from Google
CloudOps evening presentation from Google
Alistair Croll
Introduction to Google Cloud Platform Technologies
Introduction to Google Cloud Platform Technologies
Chris Schalk
Google app engine
Google app engine
Lukasz Dynowski
Mandy Waite, Warszawa marzec 2013
Mandy Waite, Warszawa marzec 2013
GeekGirlsCarrots
Google Cloud Platform 2014Q1 - Starter Guide
Google Cloud Platform 2014Q1 - Starter Guide
Simon Su
Google Technical Webinar - Building Mashups with Google Apps and SAP, using S...
Google Technical Webinar - Building Mashups with Google Apps and SAP, using S...
SAP PartnerEdge program for Application Development
Google app engine
Google app engine
Suraj Mehta
Introduction to Google's Cloud Technologies
Introduction to Google's Cloud Technologies
Chris Schalk
Static web apps by GitHub action
Static web apps by GitHub action
Seven Peaks Speaks
Google App Engine ppt
Google App Engine ppt
OECLIB Odisha Electronics Control Library
Google Cloud Technologies Overview
Google Cloud Technologies Overview
Chris Schalk
Google App Engine 7 9-14
Google App Engine 7 9-14
Tony Frame
Infinite Scale - Introduction to Google App Engine
Infinite Scale - Introduction to Google App Engine
Marian Borca
HTML5 Apps on AGL Platform with the Web Application Manager (Automotive Grade...
HTML5 Apps on AGL Platform with the Web Application Manager (Automotive Grade...
Igalia
Cloud platform overview for camping
Cloud platform overview for camping
Le Camping by Silicon Sentier
Accessing Google Cloud APIs
Accessing Google Cloud APIs
wesley chun
I Love APIs 2015: Scaling Mobile-focused Microservices at Verizon
I Love APIs 2015: Scaling Mobile-focused Microservices at Verizon
Apigee | Google Cloud
Similar a GAE Meets Django
(20)
Groovy & Grails - From Scratch to Production
Groovy & Grails - From Scratch to Production
Google App Engine
Google App Engine
Google cloud platform Introduction - 2014
Google cloud platform Introduction - 2014
CloudOps evening presentation from Google
CloudOps evening presentation from Google
Introduction to Google Cloud Platform Technologies
Introduction to Google Cloud Platform Technologies
Google app engine
Google app engine
Mandy Waite, Warszawa marzec 2013
Mandy Waite, Warszawa marzec 2013
Google Cloud Platform 2014Q1 - Starter Guide
Google Cloud Platform 2014Q1 - Starter Guide
Google Technical Webinar - Building Mashups with Google Apps and SAP, using S...
Google Technical Webinar - Building Mashups with Google Apps and SAP, using S...
Google app engine
Google app engine
Introduction to Google's Cloud Technologies
Introduction to Google's Cloud Technologies
Static web apps by GitHub action
Static web apps by GitHub action
Google App Engine ppt
Google App Engine ppt
Google Cloud Technologies Overview
Google Cloud Technologies Overview
Google App Engine 7 9-14
Google App Engine 7 9-14
Infinite Scale - Introduction to Google App Engine
Infinite Scale - Introduction to Google App Engine
HTML5 Apps on AGL Platform with the Web Application Manager (Automotive Grade...
HTML5 Apps on AGL Platform with the Web Application Manager (Automotive Grade...
Cloud platform overview for camping
Cloud platform overview for camping
Accessing Google Cloud APIs
Accessing Google Cloud APIs
I Love APIs 2015: Scaling Mobile-focused Microservices at Verizon
I Love APIs 2015: Scaling Mobile-focused Microservices at Verizon
Último
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Miguel Araújo
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Katpro Technologies
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
Martijn de Jong
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
Puma Security, LLC
Slack Application Development 101 Slides
Slack Application Development 101 Slides
praypatel2
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
apidays
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
Michael W. Hawkins
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
Anna Loughnan Colquhoun
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
Maria Levchenko
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
The Digital Insurer
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
Gabriella Davis
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
Khem
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
Antenna Manufacturer Coco
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
Safe Software
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
Principled Technologies
How to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
naman860154
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
UK Journal
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Neo4j
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
Igalia
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
Delhi Call girls
Último
(20)
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
Slack Application Development 101 Slides
Slack Application Development 101 Slides
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
How to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
GAE Meets Django
1.
使用Django创建 Google App Engine应用 林胜 linsheng.cn@gmail.com
2.
• Google App
Engine介绍 • Django介绍 • 代码示例
3.
Google App Engine介绍
4.
什么是Google App Engine •
Google的Web Hosting服务 • 将你的Web应用部署到Google的基础设施之上 • 使你的应用能 自动Scaling和load balancing • 提供数据存储服务 • 集成了Google User认证和Gmail等服务
5.
运行环境和限制 • Python 2.5.2 •
内置Django 0.96.1,并支持所有支持CGI的框架 (以及任何使用CGI适配器的WSGI框架) • 运行在Sandbox中,不能访问文件系统,不能建 立socket,不支持cron job,不能创建子进程 • 限定时间内必须返回response • 应用必须是纯Python,不支持C的扩展
6.
存储−Datastore • 基于Google BigTable,分布式存储服务 •
面向对象,非 系型数据库,不支持ORM • 相同Model可以有不同的属性 • 支持查询,排序,事务 • 不支持join, sum, avg等,不支持存储过程 • 每次查询最多返回1000条记录 • 全文检索?
7.
App Engine Service •
Google帐号认证 • Gmail(发送email) • URL Fetch • Memcached • Image (PIL)
8.
价格(免费部分) Fixed Quota Per
Day Usage Quotas 大约500万PV/月
9.
价格(收费部分) • $0.10 -
$0.12 per CPU core-hour • $0.15 - $0.18 per GB-month of storage • $0.11 - $0.13 per GB outgoing bandwidth • $0.09 - $0.11 per GB incoming bandwidth
10.
申请Google App Engine •
http://appengine.google.com/ • 通过Gmail帐号 • 通过短信认证 • 域名: http://yourapp.appspot.com • 可以通过Google Apps绑定自己的域名
11.
用途 • 学习Web 发 •
尝试各 idea, 少startup的前期投入成本 • 解决scalability问题 • App Gallery http://appgallery.appspot.com/
12.
未来计 • 对更多语言的支持 • 收费计 •
大数据量的上传和下载 • 离线处理 • 数据导入/导出
13.
Django简介
14.
Django简介 • 一个基于Python的full-stack Web框架 •
ORM, URL mapping, admin interface, template, middleware, i18n, cache... • 很快很强大
15.
为什么用Django(而不是webapp) • Google App
Engine Helper for Django • 功能更强大 • 可移植性
16.
项目示例−Blog系统 项目名称 − OnlyPython
17.
创建 发环境 • 下载Google
App Engine SDK http://code.google.com/appengine/downloads.html • 从SVN下载最新的Django源代码 http://code.djangoproject.com/svn/django/trunk/ • 下载Google App Engine Helper for Django http://code.google.com/p/google-app-engine-django/
18.
项目目录结构 --- appengine-django (app
engine helper for django 源文件目录) --- django (django源文件目录) --- onlypy (项目代码目录) --- static (静态文件目录,存放js, css, 图片等) --- app.yaml (app engine配置文件) --- index.yaml (app engine索引配置文件) --- main.py (app engine的启动脚本) --- manage.py (Django的管理脚本) --- settings.py (项目配置文件) --- urls.py (URL mapping)
19.
app.yaml application: onlypython version: 1 runtime: python api_version: 1 handlers: ‐ url: /static static_dir: static ‐ url: /.* script: main.py
20.
main.py import os import sys import logging from appengine_django import InstallAppengineHelperForDjango InstallAppengineHelperForDjango() # Google App Engine imports. from google.appengine.ext.webapp import util # Import the part of Django that we use here. import django.core.handlers.wsgi def main(): # Create a Django application for WSGI. application = django.core.handlers.wsgi.WSGIHandler() # Run the WSGI CGI handler with that application. util.run_wsgi_app(application) if __name__ == '__main__': main()
21.
settings.py TIME_ZONE = 'UTC' MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'appengine_django.auth.middleware.AuthenticationMiddleware', ) ROOT_URLCONF = 'urls' ROOT_PATH = os.path.dirname(__file__) TEMPLATE_DIRS = ( os.path.join(ROOT_PATH, 'onlypy/templates') ) INSTALLED_APPS = ( 'appengine_django', 'django.contrib.auth', 'onlypy.blog', )
22.
TODO: 添加Blog
23.
models.py from google.appengine.ext import db class Category(db.Model): name = db.StringProperty() def __str__(self): return self.name class Post(db.Model): author = db.UserProperty() title = db.StringProperty(required=True, verbose_name=u'标题') tag = db.StringProperty(verbose_name=u'标签') content = db.TextProperty(required=True, verbose_name=u'内容') create_time = db.DateTimeProperty(auto_now_add=True) update_time = db.DateTimeProperty(auto_now=True) category = db.ReferenceProperty(Category, required=True, verbose_name=u'类 ') is_published = db.BooleanProperty(verbose_name=u'已发布') def get_absolute_url(self) : return '/post/%s/'%self.key().id()
24.
forms.py from google.appengine.ext.db import djangoforms as forms from models import Post class PostForm(forms.ModelForm): class Meta: model = Post exclude = ['author']
25.
views.py def add_post(request): if request.method == 'GET': form = PostForm() if request.method == 'POST': form = PostForm(request.POST) if form.is_valid(): post = form.save() post.author = users.get_current_user() post.put() return HttpResponseRedirect('/post/add/') return render_to_response('blog/add_post.html', {'form': form}, context_instance=RequestContext(request))
26.
add_post.html {% extends "base.html" %} {% block content %} <h1>添加新文章</h1> <form name="mainForm" method="post" action=""> {{form.as_p}} <input type="submit" value="保存"/> </form> {% endblock %}
27.
urls.py from django.conf.urls.defaults import * urlpatterns = patterns('onlypy.blog.views', (r'^post/add/$', 'add_post'), )
28.
Run • cd /yourpath/onlypython/ •
python ./manage.py runserver 127.0.0.1:8000
29.
http://localhost:8000/post/add/
30.
TODO: 显示Blog列表
31.
views.py def list_post(request): posts = Post.all().order('‐create_time') if (not is_admin()): posts = posts.filter("is_published", True) return object_list(request, queryset=posts, allow_empty=True, template_name='blog/list_post.html', extra_context={'is_admin': is_admin()}, paginate_by=20)
32.
index.yaml indexes: ‐ kind: Post properties: ‐ name: is_published ‐ name: create_time direction: desc
33.
list_post.html {% extends "base.html" %} {% load markup %} {% load paginator %} {% block content %} {% for post in object_list %} <table border="0" cellspacing="0" cellpadding="0" width="100%"> <tr> <td valign="top"> <h1 style="margin‐bottom: 2px;"> <a href="/post/{{post.key.id}}"> [{{ post.category.name }}] {{ post.title }}{% if post.is_published %} {%else%}(未发布){%endif%} </a> </h1> <p style="padding:0px; margin: 0px;" class="small_font"> 类 : <a href="/category/ {{ post.category.key.id }}/">{{ post.category.name }}</a> <span style="padding‐left: 10px;">{{ post.author.nickname }}写于{{ post.create_time|date:"Y‐M‐d H:i" }}</span> </p> </td> </tr> </table> <div style="padding‐left: 30px;"> {{ post.content|markdown }} </div> {% endfor %} {% paginator %} {% endblock %}
34.
urls.py from django.conf.urls.defaults import * urlpatterns = patterns('onlypy.blog.views', (r'^post/add/$', 'add_post'), (r'^$', 'list_post'), )
35.
http://localhost:8000/
36.
项目信息 • 项目代码 http://code.google.com/p/onlypy/ •
项目演示 http://www.onlypython.com
37.
Q&A
Descargar ahora