How important is the file structure (templates and static folder) in the package of a Pyramid Project

87 views
Skip to first unread message

Raj Nathani

unread,
Sep 23, 2012, 12:43:42 PM9/23/12
to pylons...@googlegroups.com
Hey I'm kind of new to Pyramid and web frameworks in general. One of the
things I've learnt so far is that every Pyramid project created with a starter 
scaffold has a package in which there are two folders - templates and static.

Is it necessary to keep the structure this way? Would the whole thing work
fine if the folders were renamed/in-existent (with template and static files
out one level higher in the projects root folder instead)? I'm pretty sure it isn't. But that
brings me to my next question, which is about the 'static' folder, I've
seen calls from python scripts within the project which declare in some of 
way that 'static' content is served from 'static' folder. How does this help?
Does Pyramid have a different and faster way of serving files which it
knows are static?

Mike Orr

unread,
Sep 23, 2012, 3:23:44 PM9/23/12
to pylons...@googlegroups.com
On Sun, Sep 23, 2012 at 9:43 AM, Raj Nathani <raj...@hotmail.com> wrote:
> Hey I'm kind of new to Pyramid and web frameworks in general. One of the
> things I've learnt so far is that every Pyramid project created with a
> starter
> scaffold has a package in which there are two folders - templates and
> static.
>
> Is it necessary to keep the structure this way? Would the whole thing work
> fine if the folders were renamed/in-existent (with template and static files
> out one level higher in the projects root folder instead)? I'm pretty sure
> it isn't.

The main issue is specifying the paths. "myapp:templates/...", or
"templates/...", depends on the directory being inside a Python
package. MyApp/myapp is an importable Python package. MyApp isn't.
You'd have to create a relative path using __file__, or specify an
absolute path, and I'm not sure if these are compatible with
add_static_view() or renderer= anyway.

> But that
> brings me to my next question, which is about the 'static' folder, I've
> seen calls from python scripts within the project which declare in some of
> way that 'static' content is served from 'static' folder. How does this
> help?
> Does Pyramid have a different and faster way of serving files which it
> knows are static?

No, it's a convenience for the developer. The scaffolds predefine a
view for URL "/static" pointing to "myapp:static". That provides a
place for all static files to go, without the developer having to
define a view and a directory. You can of course have multiple static
directories for different purposes.

The fastest way to serve static files in production, is to arrange for
the main webserver (Apache) to serve the static directory directly
rather than passing those requests to the application.

--
Mike Orr <slugg...@gmail.com>
Reply all
Reply to author
Forward
0 new messages