librelist archives

« back to archive

static urls and migrating to a production server

static urls and migrating to a production server

From:
William Budd
Date:
2011-07-02 @ 02:54
Hello people,

What's the best practice (or just your preferred method) of turning
static urls like "url_for('static', 'ceiling_cat.jpg')" in your
(Jinja) templates into urls that point to your apache/niginx/etc media
directory on your server when migrating from the built-in Flask
development server to a production server? If this is already
documented, sorry, I just couldn't find it right now.

Will

Re: [flask] static urls and migrating to a production server

From:
Rob Mela
Date:
2011-07-03 @ 18:07
Assuming /mayapp is mapped to your Flask application, and 
url_for('status', 'ceiling_cat.jpg') produces 
/myapp/static/ceiling_cat.jpg, then ...

you could just set up a <Location /myapp/static> that resolves to a 
directory from which Apache will serve.    "ceiling_cat.jpg" would be a 
file in that directory, and would be served by Apache from there.

Don't know ngnix configs off the top of my head, but I'm sure it works 
similarly there.

On Jul 1, 2011, at 10:54 PM, William Budd wrote:

> Hello people,
> 
> What's the best practice (or just your preferred method) of turning
> static urls like "url_for('static', 'ceiling_cat.jpg')" in your
> (Jinja) templates into urls that point to your apache/niginx/etc media
> directory on your server when migrating from the built-in Flask
> development server to a production server? If this is already
> documented, sorry, I just couldn't find it right now.
> 
> Will

Re: [flask] static urls and migrating to a production server

From:
William Budd
Date:
2011-07-06 @ 03:22
Thanks and sorry about the late ack. Got caught up in something. So I
guess I just leave those "url_for('static', 'shover_bot.png')"
references in the templates untouched and set up an alias in my http
server config to preempt requests for those static urls from being
passed to Flask. Sounds like a good idea (and pretty obvious now that
I'm fully awake ^^).



On Mon, Jul 4, 2011 at 3:07 AM, Rob Mela <rob@thinkingscreen.com> wrote:
> Assuming /mayapp is mapped to your Flask application, and 
url_for('status', 'ceiling_cat.jpg') produces 
/myapp/static/ceiling_cat.jpg, then ...
>
> you could just set up a <Location /myapp/static> that resolves to a 
directory from which Apache will serve.    "ceiling_cat.jpg" would be a 
file in that directory, and would be served by Apache from there.
>
> Don't know ngnix configs off the top of my head, but I'm sure it works 
similarly there.
>
> On Jul 1, 2011, at 10:54 PM, William Budd wrote:
>
>> Hello people,
>>
>> What's the best practice (or just your preferred method) of turning
>> static urls like "url_for('static', 'ceiling_cat.jpg')" in your
>> (Jinja) templates into urls that point to your apache/niginx/etc media
>> directory on your server when migrating from the built-in Flask
>> development server to a production server? If this is already
>> documented, sorry, I just couldn't find it right now.
>>
>> Will
>
>

Re: [flask] static urls and migrating to a production server

From:
Jonathan Chen
Date:
2011-07-06 @ 23:12
But I'm still thinking that wouldn't it be better to not use url_for for
static content in production? I remember reading the docs about it.

~Jonathan C.


On Tue, Jul 5, 2011 at 8:22 PM, William Budd <will.kyoto@gmail.com> wrote:

> Thanks and sorry about the late ack. Got caught up in something. So I
> guess I just leave those "url_for('static', 'shover_bot.png')"
> references in the templates untouched and set up an alias in my http
> server config to preempt requests for those static urls from being
> passed to Flask. Sounds like a good idea (and pretty obvious now that
> I'm fully awake ^^).
>
>
>
> On Mon, Jul 4, 2011 at 3:07 AM, Rob Mela <rob@thinkingscreen.com> wrote:
> > Assuming /mayapp is mapped to your Flask application, and
> url_for('status', 'ceiling_cat.jpg') produces /myapp/static/ceiling_cat.jpg,
> then ...
> >
> > you could just set up a <Location /myapp/static> that resolves to a
> directory from which Apache will serve.    "ceiling_cat.jpg" would be a file
> in that directory, and would be served by Apache from there.
> >
> > Don't know ngnix configs off the top of my head, but I'm sure it works
> similarly there.
> >
> > On Jul 1, 2011, at 10:54 PM, William Budd wrote:
> >
> >> Hello people,
> >>
> >> What's the best practice (or just your preferred method) of turning
> >> static urls like "url_for('static', 'ceiling_cat.jpg')" in your
> >> (Jinja) templates into urls that point to your apache/niginx/etc media
> >> directory on your server when migrating from the built-in Flask
> >> development server to a production server? If this is already
> >> documented, sorry, I just couldn't find it right now.
> >>
> >> Will
> >
> >
>

Re: [flask] static urls and migrating to a production server

From:
Jesse
Date:
2011-07-06 @ 23:31
Are you thinking of this bit here?
http://flask.pocoo.org/docs/quickstart/#static-files

The wording is a little ambiguous, but it just means that Flask
shouldn't be the one serving the static files (your web server or
reverse proxy should handle those). In production, you can and should
keep using url_for for static content.

Jesse

On Wed, Jul 6, 2011 at 4:12 PM, Jonathan Chen <tamasiaina@gmail.com> wrote:
> But I'm still thinking that wouldn't it be better to not use url_for for
> static content in production? I remember reading the docs about it.
>
> ~Jonathan C.
>
>
> On Tue, Jul 5, 2011 at 8:22 PM, William Budd <will.kyoto@gmail.com> wrote:
>>
>> Thanks and sorry about the late ack. Got caught up in something. So I
>> guess I just leave those "url_for('static', 'shover_bot.png')"
>> references in the templates untouched and set up an alias in my http
>> server config to preempt requests for those static urls from being
>> passed to Flask. Sounds like a good idea (and pretty obvious now that
>> I'm fully awake ^^).
>>
>>
>>
>> On Mon, Jul 4, 2011 at 3:07 AM, Rob Mela <rob@thinkingscreen.com> wrote:
>> > Assuming /mayapp is mapped to your Flask application, and
>> > url_for('status', 'ceiling_cat.jpg') produces /myapp/static/ceiling_cat.jpg,
>> > then ...
>> >
>> > you could just set up a <Location /myapp/static> that resolves to a
>> > directory from which Apache will serve.    "ceiling_cat.jpg" would be a file
>> > in that directory, and would be served by Apache from there.
>> >
>> > Don't know ngnix configs off the top of my head, but I'm sure it works
>> > similarly there.
>> >
>> > On Jul 1, 2011, at 10:54 PM, William Budd wrote:
>> >
>> >> Hello people,
>> >>
>> >> What's the best practice (or just your preferred method) of turning
>> >> static urls like "url_for('static', 'ceiling_cat.jpg')" in your
>> >> (Jinja) templates into urls that point to your apache/niginx/etc media
>> >> directory on your server when migrating from the built-in Flask
>> >> development server to a production server? If this is already
>> >> documented, sorry, I just couldn't find it right now.
>> >>
>> >> Will
>> >
>> >
>
>

Re: [flask] static urls and migrating to a production server

From:
Rob Mela
Date:
2011-07-03 @ 18:09
Sorry -- maybe not Location -- maybe Alias

     Alias /icons/ /usr/local/apache/icons/

http://httpd.apache.org/docs/2.0/mod/mod_alias.html

On Jul 1, 2011, at 10:54 PM, William Budd wrote:

Hello people,

What's the best practice (or just your preferred method) of turning
static urls like "url_for('static', 'ceiling_cat.jpg')" in your
(Jinja) templates into urls that point to your apache/niginx/etc media
directory on your server when migrating from the built-in Flask
development server to a production server? If this is already
documented, sorry, I just couldn't find it right now.

Will