librelist archives

« back to archive

Pretty urls for static files

Pretty urls for static files

From:
Lowell Kirsh
Date:
2012-05-03 @ 01:36
I have a file (static/index.html) which I'd like to have served as
http://mydomain.com. I also would like to serve static/foobar.html as
http://mydomain.com/foobar. Is there an easy way to do this?

Thanks,
Lowell

Re: [flask] Pretty urls for static files

From:
Joseph McCullough
Date:
2012-05-03 @ 01:41
Why not make a '/foobar' route that just returns
render_template('foobar.html')?

On Wed, May 2, 2012 at 8:36 PM, Lowell Kirsh <lowellk@gmail.com> wrote:

> I have a file (static/index.html) which I'd like to have served as
> http://mydomain.com. I also would like to serve static/foobar.html as
> http://mydomain.com/foobar. Is there an easy way to do this?
>
> Thanks,
> Lowell
>



-- 
Joseph McCullough
Vert Studios - Lead Developer
903 330 5057
http://www.vertstudios.com/

Re: [flask] Pretty urls for static files

From:
Lowell Kirsh
Date:
2012-05-03 @ 01:46
Thanks. This could work. However, some issues with it: 
- I'd have to define a route for each static file. Tedious, but not too bad
- Is this efficient? I'm going to be deploying on Heroku with (probably) gunicorn.



Cheers,Lowell


On Wednesday, May 2, 2012 at 6:41 PM, Joseph McCullough wrote:

> Why not make a '/foobar' route that just returns render_template('foobar.html')?
> 
> On Wed, May 2, 2012 at 8:36 PM, Lowell Kirsh <lowellk@gmail.com 
(mailto:lowellk@gmail.com)> wrote:
> > I have a file (static/index.html) which I'd like to have served as 
http://mydomain.com. I also would like to serve static/foobar.html as 
http://mydomain.com/foobar. Is there an easy way to do this? 
> > 
> > Thanks,
> > Lowell
> > 
> 
> 
> 
> 
> 
> -- 
> Joseph McCullough
> Vert Studios - Lead Developer
> 903 330 5057
> http://www.vertstudios.com/

Re: [flask] Pretty urls for static files

From:
Simon Sapin
Date:
2012-05-03 @ 05:31
Le 03/05/2012 03:46, Lowell Kirsh a écrit :
> Thanks. This could work. However, some issues with it:
> - I'd have to define a route for each static file. Tedious, but not too bad
> - Is this efficient? I'm going to be deploying on Heroku with (probably)
> gunicorn.
>

Try this:

@app.route('/<path:filename>')
def pretty_static(filename):
     if filename.endswith('/'):
         filename += 'index.html'
     else:
         filename += '.html'
     # Add whatever logic you want
     send_from_directory('something', filename)


See http://flask.pocoo.org/docs/api/#flask.send_from_directory

Regards,
-- 
Simon Sapin

Re: [flask] Pretty urls for static files

From:
toneyalex@gmail.com
Date:
2012-05-03 @ 02:06
You can always use a view that checks to see if the file exists then serves
it, or even dynamically generates the routes.

On Wed, May 2, 2012 at 6:46 PM, Lowell Kirsh <lowellk@gmail.com> wrote:

> Thanks. This could work. However, some issues with it:
> - I'd have to define a route for each static file. Tedious, but not too bad
> - Is this efficient? I'm going to be deploying on Heroku with (probably)
> gunicorn.
>
>
> Cheers,
> Lowell
>
> On Wednesday, May 2, 2012 at 6:41 PM, Joseph McCullough wrote:
>
> Why not make a '/foobar' route that just returns
> render_template('foobar.html')?
>
> On Wed, May 2, 2012 at 8:36 PM, Lowell Kirsh <lowellk@gmail.com> wrote:
>
> I have a file (static/index.html) which I'd like to have served as
> http://mydomain.com. I also would like to serve static/foobar.html as
> http://mydomain.com/foobar. Is there an easy way to do this?
>
> Thanks,
> Lowell
>
>
>
>
> --
> Joseph McCullough
> Vert Studios - Lead Developer
> 903 330 5057
> http://www.vertstudios.com/
>
>
>


-- 
Alexander Toney
p: 509.481.5951
f: http://www.flickr.com/photos/alextoney/

Re: [flask] Pretty urls for static files

From:
Delilah Parks
Date:
2012-05-03 @ 14:27
Could you elaborate more on dynamically generating routes? Also would
Blueprints be used to reference multiple jquery files (located in a folder
other than static)?

On Wed, May 2, 2012 at 10:06 PM, toneyalex@gmail.com <toneyalex@gmail.com>wrote:

> You can always use a view that checks to see if the file exists then
> serves it, or even dynamically generates the routes.
>
> On Wed, May 2, 2012 at 6:46 PM, Lowell Kirsh <lowellk@gmail.com> wrote:
>
>> Thanks. This could work. However, some issues with it:
>> - I'd have to define a route for each static file. Tedious, but not too
>> bad
>> - Is this efficient? I'm going to be deploying on Heroku with (probably)
>> gunicorn.
>>
>>
>> Cheers,
>> Lowell
>>
>> On Wednesday, May 2, 2012 at 6:41 PM, Joseph McCullough wrote:
>>
>> Why not make a '/foobar' route that just returns
>> render_template('foobar.html')?
>>
>> On Wed, May 2, 2012 at 8:36 PM, Lowell Kirsh <lowellk@gmail.com> wrote:
>>
>> I have a file (static/index.html) which I'd like to have served as
>> http://mydomain.com. I also would like to serve static/foobar.html as
>> http://mydomain.com/foobar. Is there an easy way to do this?
>>
>> Thanks,
>> Lowell
>>
>>
>>
>>
>> --
>> Joseph McCullough
>> Vert Studios - Lead Developer
>> 903 330 5057
>> http://www.vertstudios.com/
>>
>>
>>
>
>
> --
> Alexander Toney
> p: 509.481.5951
> f: http://www.flickr.com/photos/alextoney/
>

Re: [flask] Pretty urls for static files

From:
Paul Gibbs
Date:
2012-05-03 @ 01:45
I think you'll also find the first blueprint example to have functionality
like you're describing.

 http://flask.pocoo.org/docs/blueprints/#my-first-blueprint

-Paul 


On Wednesday, May 2, 2012 at 6:41 PM, Joseph McCullough wrote:

> Why not make a '/foobar' route that just returns render_template('foobar.html')?
> 
> On Wed, May 2, 2012 at 8:36 PM, Lowell Kirsh <lowellk@gmail.com 
(mailto:lowellk@gmail.com)> wrote:
> > I have a file (static/index.html) which I'd like to have served as 
http://mydomain.com. I also would like to serve static/foobar.html as 
http://mydomain.com/foobar. Is there an easy way to do this? 
> > 
> > Thanks,
> > Lowell
> > 
> 
> 
> 
> 
> 
> -- 
> Joseph McCullough
> Vert Studios - Lead Developer
> 903 330 5057
> http://www.vertstudios.com/

Re: [flask] Pretty urls for static files

From:
Lowell Kirsh
Date:
2012-05-03 @ 02:08
Thanks. Is using render_template() fast for serving static files?


Cheers,Lowell


On Wednesday, May 2, 2012 at 6:45 PM, Paul Gibbs wrote:

> I think you'll also find the first blueprint example to have 
functionality like you're describing.
> 
>  http://flask.pocoo.org/docs/blueprints/#my-first-blueprint
> 
> -Paul 
> 
> On Wednesday, May 2, 2012 at 6:41 PM, Joseph McCullough wrote:
> 
> > Why not make a '/foobar' route that just returns 
render_template('foobar.html')?
> > 
> > On Wed, May 2, 2012 at 8:36 PM, Lowell Kirsh <lowellk@gmail.com 
(mailto:lowellk@gmail.com)> wrote:
> > > I have a file (static/index.html) which I'd like to have served as 
http://mydomain.com. I also would like to serve static/foobar.html as 
http://mydomain.com/foobar. Is there an easy way to do this? 
> > > 
> > > Thanks,
> > > Lowell
> > > 
> > 
> > 
> > 
> > 
> > 
> > -- 
> > Joseph McCullough
> > Vert Studios - Lead Developer
> > 903 330 5057
> > http://www.vertstudios.com/
> 

Re: [flask] Pretty urls for static files

From:
linnchord
Date:
2012-05-03 @ 03:51
If you have many static files to serving, you may make a url config in web
server.

a simple example in nginx:

location ~* \.(txt|xml|html|htm)$ {
root /path/to/website/root/;
}


location ~* \.(jpe?g|3gpp|mp3|gif|png|ico|swf|swf|css|js)$ {
        expires 30d;
        add_header Cache-Control public;
}



On 3 May 2012 10:08, Lowell Kirsh <lowellk@gmail.com> wrote:

> Thanks. Is using render_template() fast for serving static files?
>
>
> Cheers,
> Lowell
>
> On Wednesday, May 2, 2012 at 6:45 PM, Paul Gibbs wrote:
>
>  I think you'll also find the first blueprint example to have
> functionality like you're describing.
>
>  http://flask.pocoo.org/docs/blueprints/#my-first-blueprint
>
> -Paul
>
> On Wednesday, May 2, 2012 at 6:41 PM, Joseph McCullough wrote:
>
> Why not make a '/foobar' route that just returns
> render_template('foobar.html')?
>
> On Wed, May 2, 2012 at 8:36 PM, Lowell Kirsh <lowellk@gmail.com> wrote:
>
> I have a file (static/index.html) which I'd like to have served as
> http://mydomain.com. I also would like to serve static/foobar.html as
> http://mydomain.com/foobar. Is there an easy way to do this?
>
> Thanks,
> Lowell
>
>
>
>
> --
> Joseph McCullough
> Vert Studios - Lead Developer
> 903 330 5057
> http://www.vertstudios.com/
>
>
>
>