将CSS / CSS3 / JS链接到Google App Engine?

时间:2013-12-28 21:45:41

标签: javascript html css google-app-engine

我很难将样式表与.yaml文件链接起来。这是我的yaml文件:

我的目录看起来像这样:

| - assests - > css - js。

| - templates - >一堆我的HTML。

| main.py

| app.yaml中

如果我直接从网址上传css,它可以正常工作。但是,它无法使用目录映射。以下是我如何上传css的示例:

<link href="assets/css/animate.min.css" rel="stylesheet">
<link href="assets/css/bxslider.css" rel="stylesheet">
<link href="assets/css/magnific-popup.css" rel="stylesheet">

这是yaml文件:

    application: app 

    version: 1
    runtime: python27
    api_version: 1
    threadsafe: true 

    handlers:
    - url: /assets/css/(.*\.css)
      mime_type: text/css
      static_files: /assets/css/\1
      upload: /assets/css/(.*\.css)

    - url: /assets/css/colors(.*\.css)
      mime_type: text/css
      static_files: /assets/css/colors\1
      upload: /assets/css/colors(.*\.css)

    - url: /assets/js/(.*\.js)
      mime_type: text/js
      static_files: /assets/js/\
      upload: /assets/js/(.*\.js)

    - url: .*
      script: main.app

    libraries:
    - name: webapp2
      version: "2.5.2"
    - name: jinja2 
      version: latest 

有什么想法吗?

SOLUTION: 

application: app 
version: 1
runtime: python27
api_version: 1
threadsafe: true 

handlers:
- url: /assets/css(.*\.css)
  mime_type: text/css
  static_files: assets/css/\1
  upload: assets/css/(.*\.css)

- url: /assets/css/colors(.*\.css)
  mime_type: text/css
  static_files: assets/css/colors/\1
  upload: assets/css/colors(.*\.css)

- url: /assets/js/(.*\.js)
  mime_type: text/js
  static_files: assets/js/\1
  upload: assets/js/(.*\.js)

- url: .*
  script: main.app

libraries:
- name: webapp2
  version: "2.5.2"
- name: jinja2 
  version: latest 

1 个答案:

答案 0 :(得分:0)

两件事。首先,使样式表hrefs为绝对值(即以/开头),因为它们始终相对于Web服务路径的基础,而不是相对于任何特定页面。

其次,在app.yaml中,static_files(和static_dir)相对于应用的基本目录,因此请删除这些路径上的前导/