问题描述
我正在尝试创建登录和个人资料页面.这是 app.yaml 文件,它适用于 '/' 和 '/(anything)'.我希望路径为/user/.*",而不是/(anything)".我尝试了很多,但它只呈现页面的 html 部分.如何配置我的 app.yaml,使其使用完整的 CSS 和 JS 呈现并适用于/(anything)/(anything)"?
I'm trying to make a login and profile page. Here is the app.yaml file which works fine for '/' and '/(anything)'. Instead of '/(anything)' I would like to have the path as '/user/.*'. I tried a lot but it only renders the html part of the page. How do I configure my app.yaml, so that it renders with complete CSS and JS and works for '/(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:我有我的文件夹树,
PS: I have my folder tree as,
app.yaml
静态->CSS、JS、图像、html 文件
static->CSS,JS,Images,html files
index.yaml主应用程序
index.yamlmain.app
推荐答案
尝试类似:
- 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
,因为 (.+) 也匹配所有斜杠.如果你不希望它同时匹配,那么你需要处理正则表达式中的斜杠(字符和斜杠分开处理):
This will match /anything/file.js
as well as /anything/anything/file.js
, as well as /junk/static/hellothere/this/matches/everything/file.js
, because (.+) also matches all the slashes. If you don't want it to match both, then you need to handle the slashes in the regex (separate handling for characters and slashes):
- 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
.如果您想获得更具体的信息,可以使用:
This matches /any-thing/any_th-ing/file.js
. If you want to get more specific, you can use:
- url: /user/([A-Za-z0-9-_]+)/(.*\.js)
mime_type: text/javascript
static_files: static/\2
upload: static/(.*\.js)
匹配`/user/anything/file.js',或者:
to match `/user/anything/file.js', or:
- url: /([A-Za-z0-9-_]+)/static/(.*\.js)
mime_type: text/javascript
static_files: static/\2
upload: static/(.*\.js)
匹配/anything/static/file.js
这篇关于/user/.* 正则表达式的 Google App Engine app.yaml 配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!