Reputation: 263
Below is the code of my app.yaml
file. If I go to localhost:8080/
my index.app
loads correctly. If I go to localhost:8080/index.html
I get a 404 error. If I go to any other page for example localhost:8080/xxxx
the not_found.app
loads correctly. Why am I getting a 404 Error for the /index\.html
case?
Thanks!
application: myapp
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /index\.html
script: index.app
- url: /
script: index.app
- url: /assets
static_dir: assets
- url: /*
script: not_found.app
libraries:
- name: jinja2
version: latest
Code from index.py
class MainPage(webapp2.RequestHandler):
def get(self):
template = jinja_environment.get_template('index.html')
self.response.out.write(template.render(template_values))
app = webapp2.WSGIApplication([('/', MainPage)],
debug=True)
The fix was located in the bolded text!
Upvotes: 1
Views: 1097
Reputation: 37249
It looks like your app
variable in index
does not have a handler for index.html
. For instance:
app = webapp2.WSGIApplication([('/', MainPage)])
If your application gets routed to index
, it will look through the handlers defined and try to find a match to /index.html
. In this example, if you go to /
, it will work fine since that handler is defined; however if you go to index.html
, GAE doesn't know which class to call, and it therefore returns a 404. As a simple test, try
app = webapp2.WSGIApplication([
('/', MainPage),
('/index\.html', MainPage)
])
Since this is ostensibly a handler for anyone typing index.html
or any other permutation of index.
, you could use something like this to capture a broader array of cases (because internally, you can just route using /
if you need to):
app = webapp2.WSGIApplication([
('/', MainPage),
('/index\..*', MainPage)
])
Upvotes: 5