如何将bootstrap,css,images,js添加到谷歌应用引擎?

时间:2021-11-09 07:34:00

I have created the web application using bootstrap.I uploaded it to the google app engine.My problem is ,it doesn't show any images,js or css i have added.Please help me. My folder structure is like below.

我使用bootstrap创建了Web应用程序。我将它上传到谷歌应用程序引擎。我的问题是,它没有显示我添加的任何图像,js或css。请帮助我。我的文件夹结构如下所示。

-myapp
  -css
  -js
  -images
  -fonts
  -index.html
  -otherfiles.html....

I edited the app.yaml as below

我编辑了app.yaml如下

application: website-example
version: 1
runtime: python
api_version: 1

default_expiration: "7d"

handlers:
- url: /(.*\.(gif|png|jpg|ico|js|css|swf|xml))
  static_files: \1
  upload: (.*\.(gif|png|jpg|ico|js|css|swf|xml))

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

- url: /.*
  script: main.p

I edited the main.py as below.

我编辑了main.py,如下所示。

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class IndexHandler(webapp.RequestHandler):
    def get(self):
        if self.request.url.endswith('/'):
            path = '%sindex.html'%self.request.url

        self.redirect(path)

    def post(self):
        self.get()

application = webapp.WSGIApplication([('/.*', IndexHandler)], debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()

Please help me.I can't figure this out.

请帮帮我。我想不出来。

1 个解决方案

#1


0  

For your case, I'd use something more like:

对于你的情况,我会使用更像:

application: website-example
version: 1
runtime: python
api_version: 1

default_expiration: "7d"

handlers:
- url: /css
  static_dir: css

- url: /js
  static_dir: js

- url: /img
  static_dir: images

- /index.html
  static_files: index.html
  upload: index\.html

- url: /.*
  script: main.py

The basic idea behind the static dirs for css, js and images is that everything under those dirs will be served statically, whenever the request url starts with those urls (so, you can serve things like /img/sub_dir/foo.png)

css,js和images静态目录背后的基本思想是,每当请求url以这些url开头时,这些目录下的所有内容都将静态提供(因此,你可以提供像/img/sub_dir/foo.png这样的东西)

For the static html, I used a single file example, but you could as well put them in a separate dir and serve statically from there

对于静态html,我使用了一个单独的文件示例,但您也可以将它们放在一个单独的目录中并从那里静态地提供服务

#1


0  

For your case, I'd use something more like:

对于你的情况,我会使用更像:

application: website-example
version: 1
runtime: python
api_version: 1

default_expiration: "7d"

handlers:
- url: /css
  static_dir: css

- url: /js
  static_dir: js

- url: /img
  static_dir: images

- /index.html
  static_files: index.html
  upload: index\.html

- url: /.*
  script: main.py

The basic idea behind the static dirs for css, js and images is that everything under those dirs will be served statically, whenever the request url starts with those urls (so, you can serve things like /img/sub_dir/foo.png)

css,js和images静态目录背后的基本思想是,每当请求url以这些url开头时,这些目录下的所有内容都将静态提供(因此,你可以提供像/img/sub_dir/foo.png这样的东西)

For the static html, I used a single file example, but you could as well put them in a separate dir and serve statically from there

对于静态html,我使用了一个单独的文件示例,但您也可以将它们放在一个单独的目录中并从那里静态地提供服务