Thank you for your amazingly fast response.
Indeed your example works as described.
After digging deeper I figured that my
problem is caused by adding the "root" route to the configure.zcml:
Everything else is identical to your example and "root_view" is a
copy of "my_view" from your previous email.
When I add the root route the routes, I get either "/" or "/buckets"
for both routes depending on their order configure.zcml.
Chris McDonough wrote:
> On 6/3/09 10:29 AM, Stephan Altmueller wrote:
>> It seems that "model_url" does not work correctly with routes that
>> do not contain dynamic parts. This worked in 0.7.x but not 0.8 and 0.9.
>> Could someone tell if/what I am doing wrong.
>> Here is my routes definition in configure.zcml:
>> <route path="buckets"
>> name="allbuckets" />
>> and here is the relevant portion of the of the view code:
>> def buckets_view(context, request):
>> context_url = model_url(context, request)
>> I expected that "context_url" would be "/buckets" after the call to
>> model_url but it's "/".
>> Other routes that I am using that have a dynamic part work just fine.
>> Any pointer is appreciated.
> Hmm. I can't replicate this.
> When I have a "bfg_starter" created project and I change the configure.zcml
> looks like so:
> <configure xmlns="http://namespaces.repoze.org/bfg">
> <!-- this must be included for the view declarations to work -->
> <include package="repoze.bfg.includes" />
> ... and I change its views.py to looks like so:
> from repoze.bfg.chameleon_zpt import render_template_to_response
> from repoze.bfg.view import static
> from repoze.bfg.url import model_url
> static_view = static('templates/static')
> def my_view(context, request):
> print model_url(context, request)
> return render_template_to_response('templates/mytemplate.pt',
> request = request,
> project = 'routes_stephan')
> . and I change models.py to look like so:
> class MyModel(object):
> root = MyModel()
> def get_root(environ):
> return root
> class SomeFactory(dict):
> When I visit http://localhost:6543/buckets, I see printed to my console
> [chr...@vitaminf routes_stephan]$ ../bin/paster serve routes_stephan.ini
> Starting server in PID 73064.
> serving on 0.0.0.0:6543 view at http://127.0.0.1:6543
Repoze-dev mailing list