Re: [pylons-discuss] route_url() to generate a URL with …/#/… (for Javascript)

2018-03-06 Thread Michael Merickel
Pyramid only generates urls in the format
://://?#. Your
proposed scheme is attempting to marshal all of the data through the
anchor. The general idea of such a url that puts the query string in the
anchor is to hide that data from the server (anchors are not sent along
with requests, they are only used by the user agent).

You probably want to define a function that builds an anchor and then you
can pass it in as the _anchor value to request.route_url. The only trick
there is to know that pyramid will url-quote that value, so you'll want to
pass in an unquoted value.

def make_anchor(path, args):
return ...

request.route_url(..., _anchor=make_anchor(...))

If you're feeling fancy you can even do this with a pregenerator on the
route that you want this to work for which could take kwargs passed to
route_url and convert them into an _anchor argument under the hood. This
way you could do things like request.route_url(..., arg1='foo', arg2='bar')
and the pregenerator could strip arg1/arg2 and convert them to an _anchor
kwarg.

- Michael


On Tue, Mar 6, 2018 at 3:04 PM,  wrote:

> Hi,
>
> Using request.route_url() I’m trying to generate a URL of the form:
> _app_url/#/foo?arg=bla
>
> Using a route="/#/foo" escaped the hash, and so did "/{hash_}/foo", and
> that's according to the change comment
> 
> for Pyramid v1.9. Furthermore, an _anchor is always placed *after* query
> string arguments and must not be empty, so using _anchor="" is also not an
> option.
>
> The best I can come up with is assembling such a URL like so:
>
> _app_url + "/#/foo?" + pyramid.url.urlencode({"arg": "bla"})
>
> but that looks rather ugly.
>
> What is the recommended way of generating such a URL string? (Leaving
> aside the sense or nonsense of such a URL…)
>
> Thanks!
> Jens
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pylons-discuss+unsubscr...@googlegroups.com.
> To post to this group, send email to pylons-discuss@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/pylons-discuss/09785b15-32f1-4f9a-98f5-67b77caa0080%
> 40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pylons-discuss+unsubscr...@googlegroups.com.
To post to this group, send email to pylons-discuss@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pylons-discuss/CAKdhhwHJfLug-eA7jnZvOrkqqpT6uvZie%2BhSC9tbb2UUvGT4kg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[pylons-discuss] route_url() to generate a URL with …/#/… (for Javascript)

2018-03-06 Thread jens . troeger
Hi,

Using request.route_url() I’m trying to generate a URL of the form: 
_app_url/#/foo?arg=bla

Using a route="/#/foo" escaped the hash, and so did "/{hash_}/foo", and 
that's according to the change comment 

 
for Pyramid v1.9. Furthermore, an _anchor is always placed *after* query 
string arguments and must not be empty, so using _anchor="" is also not an 
option.

The best I can come up with is assembling such a URL like so:

_app_url + "/#/foo?" + pyramid.url.urlencode({"arg": "bla"})

but that looks rather ugly.

What is the recommended way of generating such a URL string? (Leaving aside 
the sense or nonsense of such a URL…)

Thanks!
Jens


-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pylons-discuss+unsubscr...@googlegroups.com.
To post to this group, send email to pylons-discuss@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pylons-discuss/09785b15-32f1-4f9a-98f5-67b77caa0080%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.