Steps to deploy app on Google App Engine
1) PyDev Google App Engine Project in Eclipse
2) Select 'src' folder and add to python path
3) Browse google app engine folder after unzipping
4) Hello Webapp world
5) Create index.html
6) Run Config -> Pydev Google App Run -> Browse -> app, then in second Browse -> path/to/google_app_engine/dev_appserver.py
7) Arguments -> Program Arguments -> path/to/app/src
8) Run
9) dev_appserver to check updates on startup, type no
File: helloworld.py
import webapp2
import os
from google.appengine.ext import db
from google.appengine.ext.webapp import template
class Comment(db.Model):
content = db.StringProperty(multiline=True)
date = db.DateTimeProperty(auto_now_add=True)
def comment_key():
return db.Key.from_path('comments_dir','default_comments_dir')
class MainPage(webapp2.RequestHandler):
def get(self):
comments_query = Comment.all().ancestor(comment_key()).order('-date')
comments = comments_query.fetch(10)
template_values = {'Comments':comments}
path = os.path.join(os.path.dirname(__file__),'index.html')
self.response.out.write(template.render(path, template_values))
class AddComment(webapp2.RequestHandler):
def post(self):
comment = Comment(parent=comment_key())
comment.content = self.request.get('content')
comment.put()
self.redirect('/')
app = webapp2.WSGIApplication([
('/',MainPage),
('/add',AddComment)
], debug=True)
if __name__=='__main__':
app.run()
File: index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Blog</title>
</head>
<body>
<form action="/add" method="post">
<div>
<textarea rows="3" cols="60" name="content" required></textarea>
</div>
<div>
<input type="submit" value="Add Comment">
</div>
</form>
<br>
<br>
<ul>
{% for comment in Comments %}
<li>
<blockquote>{{ comment.content }}</blockquote>
<blockquote>{{ comment.date.date.day }}/{{ comment.date.date.month }}/{{ comment.date.date.year }}</blockquote>
<blockquote>{{ comment.date.time.hour }}:{{ comment.date.time.minute }}:{{ comment.date.time.second }}</blockquote>
</li>
{% endfor %}
</ul>
</body>
</html>
1) PyDev Google App Engine Project in Eclipse
2) Select 'src' folder and add to python path
3) Browse google app engine folder after unzipping
4) Hello Webapp world
5) Create index.html
6) Run Config -> Pydev Google App Run -> Browse -> app, then in second Browse -> path/to/google_app_engine/dev_appserver.py
7) Arguments -> Program Arguments -> path/to/app/src
8) Run
9) dev_appserver to check updates on startup, type no
File: helloworld.py
import webapp2
import os
from google.appengine.ext import db
from google.appengine.ext.webapp import template
class Comment(db.Model):
content = db.StringProperty(multiline=True)
date = db.DateTimeProperty(auto_now_add=True)
def comment_key():
return db.Key.from_path('comments_dir','default_comments_dir')
class MainPage(webapp2.RequestHandler):
def get(self):
comments_query = Comment.all().ancestor(comment_key()).order('-date')
comments = comments_query.fetch(10)
template_values = {'Comments':comments}
path = os.path.join(os.path.dirname(__file__),'index.html')
self.response.out.write(template.render(path, template_values))
class AddComment(webapp2.RequestHandler):
def post(self):
comment = Comment(parent=comment_key())
comment.content = self.request.get('content')
comment.put()
self.redirect('/')
app = webapp2.WSGIApplication([
('/',MainPage),
('/add',AddComment)
], debug=True)
if __name__=='__main__':
app.run()
File: index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Blog</title>
</head>
<body>
<form action="/add" method="post">
<div>
<textarea rows="3" cols="60" name="content" required></textarea>
</div>
<div>
<input type="submit" value="Add Comment">
</div>
</form>
<br>
<br>
<ul>
{% for comment in Comments %}
<li>
<blockquote>{{ comment.content }}</blockquote>
<blockquote>{{ comment.date.date.day }}/{{ comment.date.date.month }}/{{ comment.date.date.year }}</blockquote>
<blockquote>{{ comment.date.time.hour }}:{{ comment.date.time.minute }}:{{ comment.date.time.second }}</blockquote>
</li>
{% endfor %}
</ul>
</body>
</html>
No comments:
Post a Comment