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 6932543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:43:09+00:00 2026-05-27T11:43:09+00:00

I hoped that webapp2 routing would be easy but apparently it is not (for

  • 0

I hoped that webapp2 routing would be easy but apparently it is not (for me).

This is issue is similar to webapp2 route fails as the code is pretty much the same but when I use webapp2.Route I only get 404 errors and when I use laze routing (as is the solution in the other question mentioned above) I get this colorful error message:

ERROR    2011-12-12 17:09:25,996 wsgi.py:186]
Traceback (most recent call last):
  File "/home/user/sdk/google_appengine/google/appengine/runtime/wsgi.py", line 174, in Handle
    result = handler(self._environ, self._StartResponse)
  File "/home/user/sdk/google_appengine/lib/webapp2/webapp2.py", line 1519, in __call__
    response = self._internal_error(e)
  File "/home/user/sdk/google_appengine/lib/webapp2/webapp2.py", line 1511, in __call__
    rv = self.handle_exception(request, response, e)
  File "/home/user/sdk/google_appengine/lib/webapp2/webapp2.py", line 1505, in __call__
    rv = self.router.dispatch(request, response)
  File "/home/user/sdk/google_appengine/lib/webapp2/webapp2.py", line 1253, in default_dispatcher
    return route.handler_adapter(request, response)
  File "/home/user/sdk/google_appengine/lib/webapp2/webapp2.py", line 1076, in __call__
    handler = self.handler(request, response)
TypeError: __init__() takes exactly 1 argument (3 given)
INFO     2011-12-12 17:09:26,061 dev_appserver.py:2753] "GET / HTTP/1.1" 500 -
INFO     2011-12-12 17:09:26,606 dev_appserver.py:2753] "GET /favicon.ico HTTP/1.1" 200 -

It would be nice if I could use webapp2.Route due to the extra features this brings (e.g. naming). However, it seems neither is working for me. In short this is how my code looks like:

app.yaml

application: test-app
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /favicon\.ico
  static_files: static/images/favicon.ico
  upload: static/images/favicon\.ico

- url: .*
  script: main.site_app
  login: required

libraries:
- name: django
  version: "1.2"

main.py

import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

import webapp2
import urls

site_app = webapp2.WSGIApplication(urls.SITE_URLS, debug=True)

urls.py (with webapp2.Route)

import webapp2

import handler

SITE_URLS = [
  webapp2.Route(r'^/$', handler.TestHome),
  webapp2.Route(r'^/test/(\w+)$', handler.TestPage)
]

urls.py (with webapp2 lazy routing)

import handler

SITE_URLS = [
  ('/', handler.TestHome),
  ('/test/(\w+)', handler.TestPage)
]

handler.py

import os
import webapp2
from google.appengine.ext.webapp import template

class TestHome(webapp2.RequestHandler):

  def get(self):
    self.response.write(template.render(
        os.path.join(os.path.dirname(__file__), 'templates/browse.html'), {}
      )
    )


class TestPage(webapp2.RequestHandler):

  def get(self, test_key):
    self.response.write(template.render(
        os.path.join(os.path.dirname(__file__), 'templates/browse.html'),
        {'test_key': test_key}
      )
    )

templates/browse.html

<html>
<head>
  <title>Success!</title>
</head>
<body>
Success!
{% if test_key %}- {{ test_key }}{% endif %}
</body>
</html>

What am I doing wrong? Any help/suggestions are greatly appreciated!! Thanks!

  • 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-05-27T11:43:10+00:00Added an answer on May 27, 2026 at 11:43 am

    here’s the correct regex to catch your urls

    SITE_URLS = [
        webapp2.Route(r'/', handler.TestHome),
        webapp2.Route(r'/test/<:\w+>', handler.TestPage)
    ]
    

    you can also get named route, simply by adding

     webapp2.Route(r'/test/<your_route_name_here:\w+>', handler.TestPage)
    

    and named routes are usually helpful when you have more params, and/or prefer to keep your code as clean as possible. so, for example

    webapp2.Route(r'/test/<category:\w+>/<user_id>/<day:\d+>', handler.TestPage)
    

    reflects

    class TestPage(webapp2.RequestHandler):
        def get(self, category, user_id, day):
            ...
    

    regarding that traceback – i don’t have it on my side, but i used GAE prod env (as far as i can see you’re on dev), so try to update webapp2 to the newest version, and make sure you run the code on the same py version as defined in app.yaml

    HTH.

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

Sidebar

Related Questions

I am posting this in hopes that someone might have dealt with a similar
Not too sure how to formulate my question and I hope that this is
I have some code that looks something like this: d = {'foo': True, 'bar':
Strange issue that I'm not exactly sure about...also, please feel free to correct me
I'm in troubles with TransactionPropagation.NotSupported. I believed that this propagation causes that the code
I am switching from using SQLite3 to PostgreSQL, and hoped that I could populate
This is a very strange problem, and I just hope that I can clearly
I downloaded these zip files from the link http://netbeans.org/downloads/zip.html with the hope that this
I ran into my first compiler that changes the lvalue passed to ::delete, but
Noda Time has an issue against it that the XML documentation file it ships

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.