On Sat, Nov 8, 2008 at 12:54 PM, Lukasz Szybalski <[EMAIL PROTECTED]> wrote:
>
> Hello,
>
> What needs to change to add public/ folder in front of anything that is 
> static.
>
> Currently it seems as I need to add
> Alias /css/ "/path.../"
> Alias /javascripts/ "/path.../"
> Alias /images/ "path.../"
>
> This gets complicated if I deploy 2 or more apps, then I suddenly need
> 3x usual number of aliases per each project.
>
> I would like to add
> Alias /public/ "path..tomyapp/public/"
>
> And everything in public could be referenced via
> localhost:8080/public/images/...
> localhost:8080/public/css/...
> .....
> etc..
>
> Can pylons template change to so that all public/static files are
> served through localhost/public/ folder and not via each individual
> folder?
>
> like to get something like this by default:
> http://localhost:8080/public/images/logo.png
> http://localhost:8080/public/css/style.css

You can do this by putting a public directory inside your public
directory.  If Pylons did this by default, people wouldn't be able to
put static files at the top level, including /robots.txt and
/favicon.ico which must be at the top level.

You can also use FileApp or DirectoryApp from paste.fileapp to serve a
static file from any controller.  I've only done it with FileApp.

    def attachment(self, orr_id, entry_id, filename, environ, start_response):
        """Display an attachment or thumbnail.

        Attachments are in the directory indicated by the "attachments_dir"
        config option.  A particular attachment will be under the relative
        path:  orr_id/entry_id/filename .

        Thumbnails are named "FILENAME_thumb200.jpg", and are always JPG.

        TODO: client-side caching.
        """
        orr_id = self._int_id(orr_id, "incident ID", 404)
        entry_id = self._int_id(entry_id, "entry ID", 404)
        self._REQUIRE_PERM("view_incident", orr_id=orr_id)
        attachments = config["attachments_dir"]
        path = Path(attachments, orr_id, entry_id, filename)
        app = FileApp(path)
        return app(environ, start_response)

'orr_id', 'entry_id', and 'filename' are routing variables from the
URL path.  'environ' and 'start_response' are special arguments you
can use in any controller action to return a WSGI application from an
action.  The first two lines verify the first two args are numeric and
convert them to integers.  The third line checks the user's
permission.  The fourth line reads the attachments root directory from
the configuration.  The ffifth line uses Path from the Unipath
package, which is essentially doing the same thing as os.path.join.
The sixth line creates a FileApp instance with the absolute path of
the static file.  The seventh line serves the file.

With DirectoryApp, you can instantiate it with the root directory, but
then I'm not sure how to pass the relative path when you call it.  It
reads the relative path from PATH_INFO, but I'm not sure how you get
just {*url} without the part of the URL that pointed to the action
without rewriting environ['PATH_INFO'] manually.

-- 
Mike Orr <[EMAIL PROTECTED]>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To post to this group, send email to pylons-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to