Hi,

I'm using Pyramid 1.0 for a toy project, and I'm confused about the
view lookup process. I've put a complete script showing my problem at
http://pylonshq.com/pasties/45e916782bf3e2896b94ea2e7a0fc13d

I'm using traversal, and I'd like to be able to ensure trailing
slashes on certain resources. As far as I can tell,
append_slash_notfound_view is only relevant when using URL dispatch,
so instead I'm trying to use view predicates.

I've created a marker interface for resources which should have
trailing slashes (IContainer), and the following view configuration:

@view_config(context=IContainer,
             path_info='.*[^/]$')
def add_trailing_slash(request):
    # HTTPTemporaryRedirect supports an 'add_slash' parameter, but we
    # can't use it in Pyramid because it only takes effect when the
    # exception is called (as a WSGI app), and Pyramid doesn't call
    # it.
    location = request.path_url + '/'
    if request.environ.get('QUERY_STRING'):
        location += '?' + req.environ['QUERY_STRING']
    return exc.HTTPTemporaryRedirect(location=location)


This seems to work until I add a view configuration for a specific
resource class, even though that configuration includes a path_info
predicate which only matches with a trailing slash:

# A view that should match Resource objects, but only when the URL
ends
# with a trailing slash
@view_config(context=Resource,
             path_info='.*/$')
def view_child(context, request):
    page = """
    <a href="child">Child without slash</a>
    <br>
    <a href="child/">Child with slash</a>
    """
    return Response(page)

With that view in place, if I visit "/child/" I get the page I expect,
but if I visit "/child" (no slash) I get the following error:

  predicate mismatch for view <function view_child at 0x92b93e4>

If I use the interface in both view configurations, everything is
fine, and if I use the Resource class in both places, it's also fine.
But I can't seem to use them both together.

(I've also tried custom_predicates instead of path_info, with the same
effect)

Is this expected behaviour, and if so, does anyone have any
suggestions for how I can achieve the trailing slash behaviour that I
want?

Thanks a lot,

Simon

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To post to this group, send email to pylons-devel@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en.

Reply via email to