On 12 Oct 2010, at 19:47, chris.vickerson wrote:
Hi,
I have a fairly basic question on code that can be pulled right from
the user docs. I can't get the first rule of the Submount to be
reached without getting a the 301 exception. Using the code below I
get the following exception - is this expected? Is there a way to
write the Rule to match '/blog'?
Thanks in advance for any guidance,
Chris Vickerson
# exception message
Traceback (most recent call last):
File "werkzeug_submount.py", line 17, in <module>
result = adapter.match()
File "/Library/Python/2.6/site-packages/Werkzeug-0.6.2-py2.6.egg/
werkzeug/routing.py", line 1261, in match
url_quote(path_info.lstrip('/'), self.map.charset)
werkzeug.routing.RequestRedirect: 301: Moved Permanently
# Source code #
import werkzeug
from werkzeug.routing import Submount, Map, Rule, NotFound
url_map = Map([
Rule('/', endpoint='index'),
Submount('/blog', [
Rule('/', endpoint='blog/index'),
Rule('/entry/<entry_slug>', endpoint='blog/show')
])
])
builder = werkzeug.EnvironBuilder('/blog', method='GET', data={})
environ = builder.get_environ()
adapter = url_map.bind_to_environ(environ)
result = adapter.match()
This is a redirect response. Werkzeug routing automatically redirects
urls that don't end with a slash to urls that do end in a slash. It
raises them as an exception so that you can catch them with try/except
and return the exception as a response (301, 404, etc exceptions are
also a valid response object).
You can either return the redirect, or you can change your request to
end with a slash, then it won't need to return a redirect.
>> builder = werkzeug.EnvironBuilder('/blog/', method='GET', data={})
Ed
--
You received this message because you are subscribed to the Google Groups
"pocoo-libs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pocoo-libs?hl=en.