Trying to create a custom renderer and getting error

33 views
Skip to first unread message

Zak

unread,
Jun 4, 2012, 4:42:59 PM6/4/12
to pylons-...@googlegroups.com
I'm trying to create a custom renderer like this:
config = Configurator(settings=settings)
config.add_renderer('json_with_custom_default', JSON(default=json_util.default))

But I keep getting an error "global named 'JSON' is not defined" even though I am importing json. What am I doing wrong?

Michael Merickel

unread,
Jun 4, 2012, 4:51:32 PM6/4/12
to pylons-...@googlegroups.com
so you are "importing json" via "import json" ?
and you are using some other thing called "JSON" ?
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/pylons-discuss/-/7CHOGDL4IU8J.
> To post to this group, send email to pylons-...@googlegroups.com.
> To unsubscribe from this group, send email to
> pylons-discus...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.

Zak

unread,
Jun 4, 2012, 5:04:07 PM6/4/12
to pylons-...@googlegroups.com
Yes, I have import json at the top. And, no, I'm not using anything called JSON. I think I found the class I'm trying to call in here: https://github.com/Pylons/pyramid/blob/master/pyramid/renderers.py

So how can I import that class?


On Monday, June 4, 2012 3:51:32 PM UTC-5, Michael Merickel wrote:
so you are "importing json" via "import json" ?
and you are using some other thing called "JSON" ?

On Mon, Jun 4, 2012 at 3:42 PM, Zak  wrote:
> I'm trying to create a custom renderer like this:
>
> config = Configurator(settings=settings)
>
> config.add_renderer('json_with_custom_default',
> JSON(default=json_util.default))
>
>
> But I keep getting an error "global named 'JSON' is not defined" even though
> I am importing json. What am I doing wrong?
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/pylons-discuss/-/7CHOGDL4IU8J.
> To post to this group, send email to pylons-discuss@googlegroups.com.
> To unsubscribe from this group, send email to

Zak

unread,
Jun 4, 2012, 5:34:28 PM6/4/12
to pylons-...@googlegroups.com

I think the problem is that I'm using Pyramid 1.3, not 1.4. Do you know how I can update?

Michael Merickel

unread,
Jun 4, 2012, 5:47:42 PM6/4/12
to pylons-...@googlegroups.com
You're looking at unreleased code, your options are to
maintain/install a fork, or to copy that class into your own project
or to write your own json renderer (which is very easy to do).

If you install that fork, you can "from pyramid.renderers import JSON".

On Mon, Jun 4, 2012 at 4:34 PM, Zak <zakd...@gmail.com> wrote:
>
> I think the problem is that I'm using Pyramid 1.3, not 1.4. Do you know how
> I can update?
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/pylons-discuss/-/4HXDe3d1SdoJ.
Reply all
Reply to author
Forward
0 new messages