Ответ 1
Это должно делать то, что вам нужно:
https://gist.github.com/873098
Объяснение: В App Engine Python можно использовать регулярные выражения в качестве обработчиков URL-адресов в app.yaml
и перенаправить все URL-адреса в иерархию статических файлов.
Пример app.yaml
:
application: your-app-name-here
version: 1
runtime: python
api_version: 1
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)
- url: /(.*\.txt)
mime_type: text/plain
static_files: static/\1
upload: static/(.*\.txt)
- url: /(.*\.xml)
mime_type: application/xml
static_files: static/\1
upload: static/(.*\.xml)
# 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
# redirect to 'url + /index.html' url.
- url: /(.+)
static_files: static/redirector.html
upload: static/redirector.html
# site root
- url: /
static_files: static/index.html
upload: static/index.html
Чтобы обрабатывать запросы к URL-адресам, которые не заканчиваются распознанным типом (.html
, .png
и т.д.) или /
, вам необходимо перенаправить эти запросы на URL + /
, чтобы index.html
для этого каталога. Я не знаю, как это сделать внутри app.yaml
, поэтому я добавил редиректор javascript. Это также можно сделать с помощью крошечного обработчика python.
redirector.html
:
<!DOCTYPE html>
<html lang="en">
<head>
<script language="JavaScript">
self.location=self.location + "/";
</script>
</head>
<body>
</body>
</html>