简体   繁体   English

为静态文件配置Python GAE app.yaml

[英]Configuring Python GAE app.yaml for Static Files

I am trying to get all URL references to a .css file to point to a single css directory inside of a GAE Python 2.7 project. 我正在尝试获取对.css文件的所有URL引用,以指向GAE Python 2.7项目内部的单个css目录。 For example, I want all of these URLs... 例如,我想要所有这些URL ...

http://website.com/style.css
http://website.com/a/style.css
http://website.com/a/b/c-d-e/style.css

... to point to this file in GAE... ...指向GAE中的此文件...

/css/style.css

Here is the app.yaml entry that I have been playing with: 这是我一直在玩的app.yaml条目:

- url: /.*([^/]*\.css)
  static_files: css/\1
  upload: css/.*

What I think I am doing is... 我想我正在做的是...
url: Use any URL with a .css at the end. url:使用任何以.css结尾的URL。 Group a string at the end which does not contain a forward slash and which ends in ".css". 在不包含正斜杠且结尾为“ .css”的末尾对字符串进行分组。
static_files: Use the group to reference the file within the css folder. static_files:使用该组来引用css文件夹中的文件。
upload: Select all files in the css folder as eligible files. 上载:选择css文件夹中的所有文件作为合格文件。

What am I doing wrong? 我究竟做错了什么? Points if you can explain your reply. 如果可以解释您的答复,请加分。 Bonus points if you can explain what the upload item is really for. 如果您可以解释上传项目的真正目的,则可以加分。 Thanks! 谢谢!

This worked for me: 这对我有用:

- url: /.*?([^/]*\.css)
  static_files: css/\1
  upload: css/.*\.css

First thing is in url regex. 第一件事是在URL正则表达式中。 After /.* you should put '?' 在/.*之后,您应该输入'?' because you want your regex to be lazy not greedy. 因为您想让正则表达式变得懒惰而不是贪婪。 Otherwise it'll just suck whole url to the .css part because, well, why not. 否则,它只会将整个url吸收到.css部分,因为,为什么不呢。

Second thing is - in upload part I added .css at the end. 第二件事是-在上载部分中,我最后添加了.css。 It was wild guess by me and I didn't worked out why it helped yet.. :) 这是我的一个疯狂猜测,但我还没有弄清楚它为什么有用.. :)

Hopefully this helps. 希望这会有所帮助。 Is that what you wanted? 那是你想要的吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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