我想在处理程序提供的html文件中的表单之前显示一些图像;我已经精简到下面的最小代码。
我的图像需要存储在哪里,需要在图像中指定哪些内容app.yaml
?当前未显示它们,大概是因为GAE在其他位置查找它们(我已将gif图像保存在根文件夹中)。
这是代码:
import webapp2
form="""
<img src="./c1.gif"><img src="./r1.gif">
<form action="/test">
<input name="q">
<input type="Submit">
</form>
"""
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/html'
self.response.write(form)
class TestHandler(webapp2.RequestHandler):
def get(self):
q = self.request.get("q")
self.response.headers['Content-Type'] = 'text/html'
self.response.write("Hello, still not working!")
app = webapp2.WSGIApplication([
('/', MainPage),
('/test', TestHandler)
], debug=True)
App.yaml:
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: helloworld.app
编辑:尝试了以下加上我的app.yaml其他变体,但没有运气:
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /images/*.gif
static_dir: images
- url: /.*
script: helloworld.app
您几乎完全app.yaml
正确,在静态文件处理程序中,您会找到配置静态目录处理程序所需的所有信息,但这非常简单:
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /images
static_dir: images
- url: /.*
script: helloworld.app
然后在html上,您需要写完整的路径,从root开始:
<img src="/images/c1.gif">
当然,这假设您在images
旁边有一个文件夹app.yaml
,并且其中包含上述文件。
请务必阅读链接的文档,因为您还需要注意其他细微差别(例如,静态目录是从实例外部的CDN提供服务的事实)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句