On 13 Dec 2013, at 12:01 PM, Gael Princivalle <[email protected]> wrote:
> I've read a lot of literature about routes.py, it's amazing how it can be
> powerful and complex.
> However for my simple needs I don't reach to find the solution.
>
> In my web2py root folder I have this routes.py, using the parameter-based
> system:
> routers = dict(
> BASE = dict(
> domains = {
> "mydomain1.com" : "myapp1",
> "mydomain1.com" : "myapp1",
> }
> ),
> )
>
> It works as I expect, when a user wants to go on mydomain1.com in the URL
> address it have mydomain1.com, and web2py display index from myapp1.
>
> Now I need to add this:
> When the user ask for mydomain1.com/pdf/file1.pdf, web2py search for this
> file in myapp1/static/pdf, and the URL address web2py display
> mydomain1.com/pdf/file1.pdf.
>
> Is it possible to do it with the parameter-based system, and how ?
> Do I have to add routes in the routes.py from the web2py root or from myapp1 ?
One way, not using the router: make a pdf controller, and in its default
function, open the file you want to return and:
return response.stream(file, chunk_size=4096, attachment=True,
filename='file1.pdf')
You may need to fiddle with content-type or something to control whether the
pdf gets displayed by the browser.
A more efficient way is to handle the incoming URL directly in Apache (or
whatever you're using for the front end), and bypass web2py altogether. That's
generally a good thing to do with static files in general; you just need to
rewrite the path first.
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.