Reputation: 5936
I'd like the app engine to associate index.html with the root URL and main.app with /stats. Here's my app.yaml:
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /
static_files: index.html
upload: index.html
- url: /stats.*
script: main.app
- url: /(.*)
static_files: \1
upload: (.*)
If the URL is /stats, I'd like to print a short message. Here's the code in main.py:
import logging
from flask import Flask
app = Flask(__name__)
@app.route('/stats')
def stats():
return 'Hello World!'
When I try to access /stats, the GCP log says ImportError: No module named main
. How can I fix this?
Upvotes: 0
Views: 43
Reputation: 3325
Looks like you entered in a conflict between the /stats
handler and the /(.*)
handler. As per the documentation for static_files
:
If a static file path matches a path to a script used in a dynamic handler, the script will not be available to the dynamic handler.
So, either remove the /(.*)
handler, or, as you intent to serve static files with it, I recommend using a handler like the one described in the documentation:
- url: /(.*\.(gif|png|jpg|whateverextension))$
static_files: static/\1
upload: static/.*\.(gif|png|jpg|whateverextension)$
Also, don't forget to add the Flask library to your app.yaml
file:
libraries:
- name: flask
version: 0.12
Upvotes: 4