Google App Engine静态页面Python 2.5目录等 [英] Google App Engine static pages Python 2.5 directories etc

查看:139
本文介绍了Google App Engine静态页面Python 2.5目录等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的,并计划将我的东西从付费的网络服务移动到GAE(没有动态的静态页面)。相信我已经花了无数小时试图做这个工作,但是陷入僵局,因此我排除了另外一个结果,反之亦然。



我相信这是一个简单的答案,我违反了一些基本原则。我想要的是,应用程序引擎页面(mygaeid.appspot.com)提供了一个静态着陆页,以便其他页面可用,添加一个后缀,例如mygaeid.appspot.com/oranges.html mygaeid.appspot.com/grapes.html等。



我无法实现这一点,所以我可以得到其他页面当我添加后缀例如mygaeid.appspot.com/apples.html; mygaeid.appspot.com/oranges.html但不是登陆页面或与目标网页(mygaeid.appspot.com)有一个稍微不同的yaml,但是没有访问其他页面(mygaeid.appspot.com/oranges.html等等)具有后缀。



py文件(abcdefg.py)位于下面,并且与以下两种不同的山药通用:

  import os 
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.ext.webapp导入模板

class MainHandler(webapp.RequestHandler):
def get(self,q):
如果q是None:
q ='htmdir / apples.html '

path = os.path.join(os.path.dirname(__file__),q)
self.response.headers ['Content-Type'] ='text / html'
self.response.out.write(template.render(path,{}))


def main():
application = webapp.WSGIApplication([ ('/(.*html)?',MainHandler)],debug = True)
util.run_wsgi_app(应用程序)

如果__name__ =='__main__':
main ()






使用以下yaml着陆页( mygaeid.appspot.com)工作完美(交付) ntent of apples.html),但是如果我添加了一个后缀,我无法访问该页面mygaeid.appspot.com/apples.html或mygaeid.appspot.com/static/htmdir/apples.html等,一旦我添加了后缀,它不起作用。在目录(htmdir)中,我已经将apples.html以及其他html页面oranges.html等,我不能使用这个yaml访问它们。

 应用程序:mygaeid 
版本:1
运行时:python
api_version:1

处理程序:
- url:/(.*\.(html))
static_files:static / htmdir / \ $
upload:static / htmdir /( 。* \。(html))

- url:/ css
static_dir:css

- url:/ js
static_dir:js

- url:/ images
static_dir:images

- url:。*
脚本:abcdefg.py

如果我修改了yaml,如下所示,着陆页(mygaeid.appspot.com)不起作用,但是当我添加后缀时,它可以工作完美的例如mygaeid.appspot.com/apples.html; mygaeid.appspot.com/oranges.html etc提供了相应的页面:

   -  url:/(.* \。 html))
static_files:htmdir / \1
upload:htmdir /(.* \。(html))

最后,如果我完全省略了目录,并使用相同的abcdefg.py(没有目录),以下非常简单的yaml实际上提供了我想要的结果,但是非常不友善的所有文件填充在根目录中。

 应用程序:mygaeid 
版本:1
运行时:python
api_version:1

处理程序:
- url:/(.*\.(png|js|css))
static_files:\1
上传:(。* \。(png | js | css))

- url:。*
脚本:abcedfg.py
/ pre>

任何帮助将非常感谢您了解这一点。
谢谢






感谢wooble,感谢dave我又一次回去仔细阅读了Wooble的解决方案,我需要将htmdir(包含html)放在一个名为static的目录中。 GAE是静态网站的一个伟大(免费)解决方案



您的帮助和反馈非常感谢。

  SiteDirectory 
-mygaeid
-static
-htmdir
-js
-css
-images
app.yaml
index.yaml
(py文件被删除)


解决方案

如果您在app.yaml中声明文件为静态,那么它们不适用于您的应用程序的处理程序。但是,如果它们真的是静态的,那么使用django模板引擎来渲染它们就是愚蠢的;只需在app.yaml中添加映射即可显示静态文件,其中包括一个显示apples.html for /:

  application:mygaeid 
版本:1
运行时:python
api_version:1

处理程序:
- url:/(.*\.html)
static_files:static / htmdir / \1
upload:static / htmdir /.* \.html

- url:/ css
static_dir:css

- url:/ js
static_dir:js

- url:/ images
static_dir:images

- url:/
static_files:static / htmdir / apples.html
上传:static / htmdir / apples\.html

(不需要python文件)


I am new at this and am planning to move my stuff from a paid web service to GAE (nothing dynamic just static pages). Believe me I have spent countless hours trying to make this work but am at an impasse whereby I achieve one result at the exclusion of another and visa versa.

I am sure it is a simple answer and that I am violating some basic principles. What I want is that the app engine page (mygaeid.appspot.com) delivers a static landing page such that other pages are available with the addition of a suffix e.g. mygaeid.appspot.com/oranges.html mygaeid.appspot.com/grapes.html etc.

I am unable to achieve this such that I either am able to get the other pages when I add the suffix e.g. mygaeid.appspot.com/apples.html; mygaeid.appspot.com/oranges.html but not the landing page OR with a slightly different yaml the landing page (mygaeid.appspot.com) works but there is no access to the other pages (mygaeid.appspot.com/oranges.html etc) that have a suffix.

The py file (abcdefg.py) is below and is common to the two different yamls that follow:

import os
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.ext.webapp import template

class MainHandler(webapp.RequestHandler):
  def get (self, q):
    if q is None:
      q = 'htmdir/apples.html'

    path = os.path.join (os.path.dirname (__file__), q)
    self.response.headers ['Content-Type'] = 'text/html'
    self.response.out.write (template.render (path, {}))


def main ():
  application = webapp.WSGIApplication ([('/(.*html)?', MainHandler)], debug=True)
  util.run_wsgi_app (application)

if __name__ == '__main__':
  main ()


Using the following yaml the landing page (mygaeid.appspot.com) works perfectly (delivering the content of apples.html), but I cannot access the page if I add a suffix e.g. mygaeid.appspot.com/apples.html or mygaeid.appspot.com/static/htmdir/apples.html etc, as soon as I add the suffix it does not work. In the directory (htmdir) I have placed apples.html along with other html pages e.g. oranges.html etc and I cannot access any of them with this yaml.

application: mygaeid
version: 1
runtime: python
api_version: 1

handlers:
- url: /(.*\.(html))
  static_files: static/htmdir/\1
  upload: static/htmdir/(.*\.(html))

- url: /css
  static_dir: css

- url: /js
  static_dir: js

- url: /images
  static_dir: images

- url: .*
  script: abcdefg.py

If I modify the yaml as follows then the landing page (mygaeid.appspot.com) does not work but when I add the suffixes then it works perfectly e.g. mygaeid.appspot.com/apples.html; mygaeid.appspot.com/oranges.html etc deliver the appropriate pages:

- url: /(.*\.(html))
  static_files: htmdir/\1
  upload: htmdir/(.*\.(html))

Finally if I dispense with the directories altogether and using the same abcdefg.py (without the directory) the following very simple yaml actually delivers the results I want but is very unruly as all the files are stuffed in the root directory.

application: mygaeid
version: 1
runtime: python
api_version: 1

handlers:
- url: /(.*\.(png|js|css))
  static_files: \1
  upload: (.*\.(png|js|css))

- url: .*
  script: abcedfg.py

any help would be much appreciated on figuring this out. thanks


thanks wooble and thanks dave I went back yet again and carefully read the logs Wooble's solution works but I needed to put the htmdir (that contains the html) inside a directory called static. GAE is a great (and free) solution for static websites

your help and feedback is very much appreciated

SiteDirectory
-mygaeid
  -static
    -htmdir
  -js
  -css
  -images
 app.yaml
 index.yaml
(py file was removed)

解决方案

If you declare files as static in app.yaml, they are not available to your application's handlers.

However, if they're really static, using the django template engine to "render" them is kind of silly; just add mappings in app.yaml to display the static files, including one to display apples.html for /:

application: mygaeid
version: 1
runtime: python
api_version: 1

handlers:
- url: /(.*\.html)
  static_files: static/htmdir/\1
  upload: static/htmdir/.*\.html

- url: /css
  static_dir: css

- url: /js
  static_dir: js

- url: /images
  static_dir: images

- url: /
  static_files: static/htmdir/apples.html
  upload: static/htmdir/apples\.html

(no python files needed)

这篇关于Google App Engine静态页面Python 2.5目录等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆