List Info

Thread: How to override static url from controller?




How to override static url from controller?
country flaguser name
United States
2007-03-02 04:08:59
Hi, is it possible to return content from controller rather
than
"real" static file? Take my case. I have a
test.txt file in /static/
and a expose method static, if I request url http://localhos
t:8080/static/test.txt,
it returns "In file test.txt". But I do need the
content returned from
controller, that is "In controller". Any idea?

# /path/to/static/test.txt
In file test.txt

# Controller.py
class Root(controllers.RootController):
    expose()
    def static(name):
        return 'In controller'


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: How to override static url from controller?
country flaguser name
United Kingdom
2007-03-02 04:24:09
Olli Wang wrote:
> Hi, is it possible to return content from controller
rather than
> "real" static file? Take my case. I have a
test.txt file in /static/
> and a expose method static, if I request url http://localhos
t:8080/static/test.txt,
> it returns "In file test.txt". But I do need
the content returned from
> controller, that is "In controller". Any
idea?
> 
> # /path/to/static/test.txt
> In file test.txt
> 
> # Controller.py
> class Root(controllers.RootController):
>     expose()
>     def static(name):
>         return 'In controller'
> 

It's a bit confusing. I will assume that you wanna return
the content of
test.txt from the controller manually instead of the static
tool. Right?

If that's so you can call the
cherrypy.lib.static.serve_file() [1]
method from the controller. Or you can use the capacity of
the static
tool to be applied as a page handler itself [2]

- Sylvain

[1]
http://www.c
herrypy.org/wiki/StaticContent#Servestaticcontentfromapageha
ndlerbypassingthestatictools
[2] http://www.cherrypy.org/browser/trunk/cherrypy/_c
ptools.py#L130

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )