Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8500263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:53:52+00:00 2026-06-11T00:53:52+00:00

I have tried everything but it seems that you cannot get a catch all

  • 0

I have tried everything but it seems that you cannot get a catch all url…

- url: /.*
  script: not_found.py  

…to work on urls that are based on static directory paths. eg. I can type in http://www.foobar.com/asdas/asd/asd/asd/ad/sa/das/d and I can get a nice custom 404 page. But if I alter a static path url like http://www.foobar.com/mydir/mydir/mypage.html, I just get the horrible generic 404….

Error: Not Found

The requested URL /mydir/mydir/mypage.html was not found on this server.

… I would like to alter whatever catches the url in directory paths and writes the 404. This appears the only way to get a consistent custom 404 page in GAE Python.

Can anyone help? I have written my website from scratch and have a very limited knowledge of Python. Achieving a consistent custom 404 is the only thing I cannot seem to overcome.

EDIT/ADD : OK I’ve added the kind suggestion of @Lipis , and gone through getting started which which thankfully has given me a much better understanding of classes (I sadly can’t vote it up yet). But! I am using a .py script found on the net and I think the NotFound class is interfering with the class that gives my index page, because now my index page is the 404 page specified by the Jinja! I have very little understanding of MainHandler so I may have to give up for now.

import os
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app

import jinja2


class MainHandler(webapp.RequestHandler):
  def get (self, q):
    if q is None:
      q = 'index.html'

    path = os.path.join (os.path.dirname (__file__), q)
    self.response.headers ['Content-Type'] = 'text/html'
    self.response.out.write (template.render (path, {}))


class NotFound(webapp.RequestHandler):
      def post(self):
         # you need to create the not_found.html file
         # check Using Templates from Getting Started for more

         jinja_environment = jinja2.Environment(
         loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))

         template = jinja_environment.get_template('404.html')
         self.response.out.write(template.render(template_values))


def main ():
  application = webapp.WSGIApplication ([('/(.*html)?', MainHandler),('/.*', NotFound)], 
                                      debug=True)

  util.run_wsgi_app (application)


if __name__ == '__main__':
  main ()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:53:53+00:00Added an answer on June 11, 2026 at 12:53 am

    For better understanding I’ll make some modifications on the Getting Started example which I assume that you have done it and you made some experiments with it.

    It’s not a good idea to have the static file for all the not found pages in the app.yaml since most likely you would like to show something more dynamic and usually the - url: /.* should be handled within your app.

    In this example we are going to add a new RequestHandler for all your not found pages

    import jinja2
    import os
    # more imports
    
    jinja_environment = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))
    
    class MainPage(webapp2.RequestHandler):
        def get(self):
             template = jinja_environment.get_template('index.html')
             self.response.out.write(template.render(template_values))
    
    class NotFound(webapp.RequestHandler):
        def get(self):
             # you need to create the not_found.html file
             # check Using Templates from Getting Started for more
             template = jinja_environment.get_template('not_found.html')
             self.response.out.write(template.render(template_values))
    
    application = webapp.WSGIApplication(
                                         [('/', MainPage),
                                          ('/.*', NotFound)], # <-- This line is important
                                          debug=True)
    

    But in order to make the jinja2 templates work, follow carefully the modifications that you need to do in Using Templates section from the Getting Started.

    The order in the URL mapping is very important so this catch all regular expression (/.*) should be always the last one, because otherwise all the other rules will be skipped.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Cant get this script to work with my menu really have tried everything any
I have nearly tried everything but cannot figure out what is wrong. I have
Having an issue here that I have tried everything I can think of but
This might get a little confusing as I have tried everything to make this
Hi I have tried for 2 hours everything that I could find on the
It seems like it should be so simple, but I simply cannot get this
I cannot seem to get this to work. I have a small JS file
I have tried everything in the book and EVERYTHING I could find on how
I have tried everything, searched the net for two hours or even more and
I'm having trouble making python print out texts properly aligned. I have tried everything

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.