简体   繁体   中英

how to add bootstrap, css, images ,js into google app engine?

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.

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

I edited the app.yaml as below

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.

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.

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM