Good day,
I'm currently trying to create something incredibly simple in Google AppEngine. The goal is to create a simple photo-sharing application that will connect to my iPhone application. All of this has learning experience for both Python and Objective-C.
(I was a PHP programmer for some time).
The goal is to create a URL that looks like this: / img / {{model.key.id}}
The problem is that it seems to me that I am not making a python script, either I am either getting an error or just not getting anything to display a template on my page that is wrapped in a FOR statement.
My App.yaml file:
application: randomwebappname
version: 1
runtime: python
api_version: 1
handlers:
- url: /media
static_dir: media
- url: /b/.*
script: beta.py
login: required
- url: /.*
script: main.py
My model (inside beta.py):
class Photo(db.Model):
author = db.StringProperty()
title = db.StringProperty()
slugline = db.StringProperty()
content = db.StringProperty(multiline=True)
coordinates = db.StringProperty()
avatar = db.BlobProperty()
date = db.DateTimeProperty(auto_now_add=True)
My class to view image page:
class ViewPage(webapp.RequestHandler):
def get(self, id):
template_values = {
'image': image,
}
path = os.path.join(os.path.dirname(__file__), 'templates/view.html')
self.response.out.write(template.render(path, template_values))
, . , key.name key.id URL:
photos = db.Query(Photo).filter('key', slug).fetch(limit=1)
photos = Photo.get_by_key_name(id)
photos = Photo.get_by_key_name(key)
key = db.Key.from_path('Photo', id)
photos = db.GqlQuery("SELECT * FROM Photo WHERE __key__ = :key", key=key)
photos = db.get(photo_key)
photos = self.request.get("id")
URL-:
application = webapp.WSGIApplication([
('/b/', HomePage),
('/b/upload', UploadPage),
('/b/add', MainPage),
('/b/img', Image),
('/b/img/([-\w]+)', ViewPage),
('/b/submit', Submission)
], debug=True)
:
{% for photo in photos %}
<img alt="" title="" src="img?img_id={{ photo.key }}" alt="main image" />
{% endfor %}
, - , , - , , . PHP, AppEngine, , Python.
, . GQL, , , /img/id.
( gals)? !
# 1:
, :
class Image (webapp.RequestHandler):
def get(self):
photo = db.get(self.request.get("img_id"))
if photo.avatar:
self.response.headers['Content-Type'] = "image/png"
self.response.out.write(photo.avatar)
else:
self.response.out.write("No image")
, , , , /img /img/ . . Key, key.id:
URL:
('/b/i', ViewPage)
ViewPage:
class ViewPage(webapp.RequestHandler):
def get(self):
image = db.get(self.request.get("id"))
template_values = {
'image': image,
}
path = os.path.join(os.path.dirname(__file__), 'templates/view.html')
self.response.out.write(template.render(path, template_values))
... ( ..), URL-:
/b/i? img_id = {{image.key}}
, , , :
/b/img/ {{image.key.id}}
# 2: ViewPage, URL:
class ViewPageV2(webapp.RequestHandler):
def get(self, id):
images = [ db.get(id) ]
template_values = {
'image': image,
}
path = os.path.join(os.path.dirname(__file__), 'templates/view.html')
self.response.out.write(template.render(path, template_values))
URL: ('/b/image/([-\w] +)', ViewPageV2),
, "1" , .
alt text http://img215.imageshack.us/img215/9123/screenshot20091130at937.png
alt text http://img215.imageshack.us/img215/2207/screenshot20091130at938.png
, !