I'm having trouble getting static .html
pages loaded for my Python app. When I click on a link like index.html , I get a blank page and on the server log a 404 error. This is the same for other static .html
files such as about.html .
The application works bar the static files. I've tried looking in numerous places, but I cannot seem to get the .html pages up. ie
INFO 2011-04-16 17:26:33,655 dev_appserver.py:3317] "GET / terms.html HTTP/1.1" 404 -
yaml:
application: quote
version: 1
runtime: python
api_version: 1
handlers:
- url: /index\.html
script: index.py
- url: /
script: index.py
- url: /(.*\.(html))
static_files: static/\1
upload: static/HTML/(.*\.(html))
- url: /favicon.ico
static_files: static/images/favicon.ico
upload: images/favicon.ico
mime_type: image/x-icon
- url: /css
static_dir: static/css
- url: /images
static_dir: static/images
- url: /js
static_dir: static/js
My static files are located in static/HTML and index.html is in the main folder.
I have also tried this, but it seems to make no difference at all:
- url: /favicon.ico
static_files: static/images/favicon.ico
upload: images/favicon.ico
mime_type: image/x-icon
- url: /css
static_dir: static/css
- url: /images
static_dir: static/images
- url: /js
static_dir: static/js
- url: /(.*\.(html))
static_files: static/\1
upload: static/HTML/(.*\.(html))
- url: /index\.html
script: index.py
- url: /
script: index.py
Keep your HandlerScripts below the Static Directory handling portion. IOW, just move this to the last.
- url: /index\.html
script: index.py
- url: /
script: index.py
Put an /HTML
in your static_files path:
- url: /(.*\.(html))
static_files: static/HTML/\1
upload: static/HTML/(.*\.(html))
You don't have to define each directory seperatly in you yaml file
handlers:
- url: /static
static_dir: my_application/static
Then in your relevant html file that you will render with django you can call your static content for example like
<script src="/static/less_lib.min.js"></script>
You must properly indent your YAML.
Provided
script at incorrect level
handlers:
- url: /index\.html
script: index.py
json equivalent
{
"handlers": [
{
"url": "/index\\.html"
}
],
"script": "index.py"
}
Indented
script at correct level
handlers:
- url: /index\.html
script: index.py
json equivalent
{
"handlers": [
{
"url": "/index\\.html",
"script": "index.py"
}
]
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.