【问题标题】:Google App Engine app.yaml configuration for /user/.* regex/user/.* 正则表达式的 Google App Engine app.yaml 配置
【发布时间】:2014-10-10 08:39:24
【问题描述】:

我正在尝试创建登录和个人资料页面。这是适用于“/”和“/(任何)”的 app.yaml 文件。而不是 '/(anything)' 我希望路径为 '/user/.*'。我尝试了很多,但它只呈现页面的 html 部分。如何配置我的 app.yaml,使其以完整的 CSS 和 JS 呈现并适用于“/(anything)/(anything)”?

application: My-App-name
version: 1
runtime: python27
api_version: 1
threadsafe: yes


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

- url: /(.*\.html)
  mime_type: text/html
  static_files: static/\1
  upload: static/(.*\.html)

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

 image files
- url: /(.*\.(bmp|gif|ico|jpeg|jpg|png))
  static_files: static/\1
  upload: static/(.*\.(bmp|gif|ico|jpeg|jpg|png))

# index files
- url: /(.+)/
  static_files: static/\1/index.html
  upload: static/(.+)/index.html


# site root

- url: /.*
  script: main.app

#- url: /user/.*
#  script: main.app

libraries:
- name: jinja2
  version: latest

PS:我的文件夹树为,

app.yaml

静态->CSS、JS、图片、html文件

index.yaml 主应用程序

【问题讨论】:

    标签: google-app-engine python-2.7 app.yaml


    【解决方案1】:

    尝试类似:

    - url: /(.+)/(.*\.js)
      mime_type: text/javascript
      static_files: static/\2
      upload: static/(.*\.js)
    

    这将匹配 /anything/file.js 以及 /anything/anything/file.js/junk/static/hellothere/this/matches/everything/file.js,因为 (.+) 也匹配所有斜杠。如果您不希望它同时匹配两者,那么您需要处理正则表达式中的斜杠(字符和斜杠分开处理):

    - url: /([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/(.*\.js)
      mime_type: text/javascript
      static_files: static/\3
      upload: static/(.*\.js)
    

    这匹配/any-thing/any_th-ing/file.js。如果您想更具体,可以使用:

    - url: /user/([A-Za-z0-9-_]+)/(.*\.js)
      mime_type: text/javascript
      static_files: static/\2
      upload: static/(.*\.js)
    

    匹配`/user/anything/file.js',或者:

    - url: /([A-Za-z0-9-_]+)/static/(.*\.js)
      mime_type: text/javascript
      static_files: static/\2
      upload: static/(.*\.js)
    

    匹配/anything/static/file.js

    【讨论】:

    • 嘿哥们,上传参数有什么用?我的意思是现在我正在使用 Django,并且我已经运行 collectstatic 将所有文件收集到一个地方。那么它是通过 gcloud 上传还是服务器会自动运行命令?
    • 它不工作你能帮我解决我的问题吗?我在这里发了一个问题stackoverflow.com/questions/48849370/… ,我已经完成了你在这里告诉我要做的事情,我想问 app.yaml 和 static 文件夹应该在同一个目录下吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-16
    • 2022-01-24
    • 2019-03-19
    • 2013-04-09
    • 1970-01-01
    • 2020-12-28
    相关资源
    最近更新 更多