Google App Engine Static Pages Python 2.5 Directories Etc
Solution 1:
If you declare files as static in app.yaml, they are not available to your application's handlers.
However, if they're really static, using the django template engine to "render" them is kind of silly; just add mappings in app.yaml to display the static files, including one to display apples.html for /:
application:mygaeidversion:1runtime:pythonapi_version:1handlers:-url:/(.*\.html)static_files:static/htmdir/\1upload:static/htmdir/.*\.html-url:/cssstatic_dir:css-url:/jsstatic_dir:js-url:/imagesstatic_dir:images-url:/static_files:static/htmdir/apples.htmlupload:static/htmdir/apples\.html
(no python files needed)
Solution 2:
Woobie has the right answer. Let me phrase it differently.
When you put .html in static_files
, they're served by separate services that are dedicated to serving static content. Your app will not be able to see those files. The app can only see files that are resources.
Django templates must be resources, not static files. Otherwise, the application can't see them, and the template.render(path, ...
will fail.
A next step to getting your problem solved is (if you haven't done so aleady) is to update your post to show your current app.yaml
, and also to show us what's being reported up in the application's logs.
Solution 3:
There are technical reasons why it works this way
The app.yaml config functions in a very simple top->bottom procedural manner.
Matching happens in the following order:
1. - url:/(.*\.(html))static_files:static/htmdir/\1upload:static/htmdir/(.*\.(html))2. - url:/cssstatic_dir:css3. - url:/jsstatic_dir:js4. - url:/imagesstatic_dir:images5. - url:.*script:abcdefg.py
To put it simply, if the file has a .html suffix it gets matched in step 1 and reroutes that request from mygaeid.appspot.com/.html to mygaeid.appspot.com/htmdir/.html. The *.html handler in step 5 never gets hit because all *.html routes are already spoken for.
In addition -- as the answers have already covered -- directories marked as static will not be available locally to your app handlers. I'll try to address the technical reasons why.
app.yaml acts as a configuration file for GAE's reverse proxy. Static files only change when they're uploaded so they're ideal for caching. By immediately pushing the static files to a cache server when they're deployed, GAE increases loading performance and removes unnecessary load from the app servers.
There's a good reason that static requests are counted separately and cost less than regular app requests. Every time you request a static file you're essentially pulling fetching the file from GAE's CDN. If you were to only fetch static files, then your server would have no reason to spool up in the first place.
The obvious downside to that approach is that those files don't physically exist on the same server as your app so you can't fetch or upload them directly in your app.
Note: Also following what other answers have covered. Don't mark your template folder as static. When your app goes to load the template -- instead of grabbing it from an adjacent directory -- it'll have to send out a web request and fetch the file from a remote location. Obviously, fetching a remote file instead of a local file is going to increase load time and latency.
Post a Comment for "Google App Engine Static Pages Python 2.5 Directories Etc"