Li3*_*3ro 0 python django google-app-engine yaml
我需要在这个服务器中提出一些基本功能:
我已经成功地分别实现了所有这些,现在当我开始一起工作时,由于设计糟糕,app.yaml url路径出现了问题.
app.yaml看起来像:
runtime: python
handlers:
- url: /(.+)
static_files: images/\1
upload: images/(.*)
- url: /.*
script: kserver.py
Run Code Online (Sandbox Code Playgroud)
kserver.py:
class StartPage(webapp.RequestHandler):
def get(self):
select_items = db.GqlQuery( "SELECT * FROM Registration" )
upload_url = blobstore.create_upload_url('/upload')
self.response.out.write(template.render("tst.html", {'select_items': select_items}))
class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
def post(self):
upload_files = self.get_uploads('file')
image = self.request.get("img")
photo = Photo()
photo.imageblob = db.Blob(image)
photo.put()
blob_info = upload_files[0]
self.redirect('/serve/%s' % blob_info.key())
class DownloadImage(webapp.RequestHandler):
def get(self):
photo= db.get(self.request.get("photo_id"))
if photo:
self.response.headers['Content-Type'] = "image/jpeg"
self.response.out.write(photo.imageblob)
else:
self.response.out.write("Image not available")
class Sender(webapp.RequestHandler):
def post(self):
...
...
self.response.headers['Content-Type'] = 'text/html' # reply with 200 OK
self.response.set_status( 200,"OK" )
...
...
class TokenService(webapp.RequestHandler):
def post(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.set_status( 200,"Registration accepted" )
...
application = webapp.WSGIApplication([('/', StartPage),
('/sender',Sender),
('/upload', UploadHandler),
('/i', DownloadImage),
('/serve/([^/]+)?', ServeHandler),
('/token',TokenService)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
Run Code Online (Sandbox Code Playgroud)
这是tst.html:
<html>
<body>
<select name="accountName">
<option value=\"ALL\">ALL</option>
{% for item in select_items %}
<option value="{{ item.accountName }}">{{ item.accountName }}</option>
{% endfor %}
</select>
<form action="sender" method="POST">
<input type="text" id="TextEditBox_1">
<input type="submit" name="submit">
<input type="file" name="img" id="Choose_file">
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
注意,Identation很好,它只是代码的一部分.
在项目中,我有一个图像目录,其中包含app.ico和背景图像(静态)
好的,现在问题是我进入GAE日志:
Static file referenced by handler not found: images/token
Static file referenced by handler not found: images/sender
Run Code Online (Sandbox Code Playgroud)
这不是故意的.它应该在'/'我认为
和
"/token 404 48ms 0kb No handlers matched this URL."
Run Code Online (Sandbox Code Playgroud)
此外,当点击"发送"时,它会将我重定向到一个新页面:
The requested URL /sender was not found on this server.
Run Code Online (Sandbox Code Playgroud)
这个/ token是来自外部的POST来注册到服务器 - 服务器而不是db中的商店注册.当按下"发送"按钮时,它应该使用这个db.register标记.
任何有关该主题的评论都是最受欢迎的.感谢名单!
app.yaml中的模式过于笼统:
- url: /(.+)
static_files: images/\1
upload: images/(.*)
Run Code Online (Sandbox Code Playgroud)
几乎任何东西都匹配,因此代码处理的请求永远不会到达那里.尝试这样的事情:
- url: /(.*\.(gif|png|jpg))
static_files: static/\1
upload: static/(.*\.(gif|png|jpg))
Run Code Online (Sandbox Code Playgroud)
它只处理以gif,png或jpg结尾的文件.
| 归档时间: |
|
| 查看次数: |
162 次 |
| 最近记录: |