librelist archives

« back to archive

How to allow access to files stored in a particular directory on the flask/python server

How to allow access to files stored in a particular directory on the flask/python server

From:
Norbert Markowicz
Date:
2012-11-10 @ 16:39
Hi all,

How do I enable flask so that it allows  the .index html file access to the
files in a particular directory  say:  img  (static, templates, img
directories are in my main folder)

for example when CSS accesses: background: url(/img/select-icons.png)
or standard html access:
<a href="img/IMG_0009.JPG'">Click test</a>

Thanks in advance

Re: [flask] How to allow access to files stored in a particular directory on the flask/python server

From:
Markus Unterwaditzer
Date:
2012-11-10 @ 17:22
On 2012-11-10 17:39, Norbert Markowicz wrote:
> Hi all,
>
> How do I enable flask so that it allows  the .index html
> file access to the files in a particular directory  say:  img
>  (static, templates, img directories are in my main folder)
>
>  for example when CSS accesses: background: 
> url(/img/select-icons.png) 
> or standard html access:
>
> <a href="img/IMG_0009.JPG'">Click test</a>
>
>  Thanks in advance

It surely would be easiest to use the "static" folder for this. It is 
described right in the quickstart: 
http://flask.pocoo.org/docs/quickstart/#static-files

Re: [flask] How to allow access to files stored in a particular directory on the flask/python server

From:
Juliob
Date:
2012-11-10 @ 17:54
I had the same problem and this was my solution

http://librelist.com/browser//flask/2012/11/2/show-images-from-another-folder-than-static/

El 10/11/2012, a las 18:22, Markus Unterwaditzer 
<markus@unterwaditzer.net> escribió:

> On 2012-11-10 17:39, Norbert Markowicz wrote:
>> Hi all,
>> 
>> How do I enable flask so that it allows  the .index html
>> file access to the files in a particular directory  say:  img
>>  (static, templates, img directories are in my main folder)
>> 
>> for example when CSS accesses: background: 
>> url(/img/select-icons.png) 
>> or standard html access:
>> 
>> <a href="img/IMG_0009.JPG'">Click test</a>
>> 
>> Thanks in advance
> 
> It surely would be easiest to use the "static" folder for this. It is 
> described right in the quickstart: 
> http://flask.pocoo.org/docs/quickstart/#static-files

Re: [flask] How to allow access to files stored in a particular directory on the flask/python server

From:
Norbert Markowicz
Date:
2012-11-10 @ 19:27
Thanks for the insights fellas. I was hoping to avoid the need to specify:

url_for('static', filename='XXXX')

-Norbert
On Sat, Nov 10, 2012 at 12:54 PM, Juliob <juliob@gmx.com> wrote:

> I had the same problem and this was my solution
>
> 
http://librelist.com/browser//flask/2012/11/2/show-images-from-another-folder-than-static/
>
> El 10/11/2012, a las 18:22, Markus Unterwaditzer <markus@unterwaditzer.net>
> escribió:
>
> On 2012-11-10 17:39, Norbert Markowicz wrote:
>
> Hi all,
>
>
> How do I enable flask so that it allows  the .index html
>
> file access to the files in a particular directory  say:  img
>
>  (static, templates, img directories are in my main folder)
>
>
> for example when CSS accesses: background:
>
> url(/img/select-icons.png)
>
> or standard html access:
>
>
> <a href="img/IMG_0009.JPG'">Click test</a>
>
>
> Thanks in advance
>
>
> It surely would be easiest to use the "static" folder for this. It is
> described right in the quickstart:
> http://flask.pocoo.org/docs/quickstart/#static-files
>
>

Re: [flask] How to allow access to files stored in a particular directory on the flask/python server

From:
Jeffrey Tratner
Date:
2012-11-10 @ 19:34
If you're concerned about verbosity, why not just write a mini jinja
function that just wraps url_for so you end up with something like
static_for(filename)?
On Nov 10, 2012 2:30 PM, "Norbert Markowicz" <norbert.markowicz@gmail.com>
wrote:

> Thanks for the insights fellas. I was hoping to avoid the need to specify:
>
> url_for('static', filename='XXXX')
>
> -Norbert
> On Sat, Nov 10, 2012 at 12:54 PM, Juliob <juliob@gmx.com> wrote:
>
>> I had the same problem and this was my solution
>>
>> 
http://librelist.com/browser//flask/2012/11/2/show-images-from-another-folder-than-static/
>>
>> El 10/11/2012, a las 18:22, Markus Unterwaditzer <
>> markus@unterwaditzer.net> escribió:
>>
>> On 2012-11-10 17:39, Norbert Markowicz wrote:
>>
>> Hi all,
>>
>>
>> How do I enable flask so that it allows  the .index html
>>
>> file access to the files in a particular directory  say:  img
>>
>>  (static, templates, img directories are in my main folder)
>>
>>
>> for example when CSS accesses: background:
>>
>> url(/img/select-icons.png)
>>
>> or standard html access:
>>
>>
>> <a href="img/IMG_0009.JPG'">Click test</a>
>>
>>
>> Thanks in advance
>>
>>
>> It surely would be easiest to use the "static" folder for this. It is
>> described right in the quickstart:
>> http://flask.pocoo.org/docs/quickstart/#static-files
>>
>>
>

Re: [flask] How to allow access to files stored in a particular directory on the flask/python server

From:
Joe Esposito
Date:
2012-11-10 @ 19:54
Here's the simple code snippet I've used to add a `static_for` function.
Also works in your templates.


def static_for(filename, endpoint='.static'):
    """Gets the specified static file."""
    return url_for(endpoint, filename=filename)

app.jinja_env.globals.update(static_for=static_for)



https://gist.github.com/4052265

On Sat, Nov 10, 2012 at 2:34 PM, Jeffrey Tratner <jtratner@gmail.com> wrote:

> If you're concerned about verbosity, why not just write a mini jinja
> function that just wraps url_for so you end up with something like
> static_for(filename)?
>  On Nov 10, 2012 2:30 PM, "Norbert Markowicz" <norbert.markowicz@gmail.com>
> wrote:
>
>> Thanks for the insights fellas. I was hoping to avoid the need to specify:
>>
>> url_for('static', filename='XXXX')
>>
>> -Norbert
>> On Sat, Nov 10, 2012 at 12:54 PM, Juliob <juliob@gmx.com> wrote:
>>
>>> I had the same problem and this was my solution
>>>
>>> 
http://librelist.com/browser//flask/2012/11/2/show-images-from-another-folder-than-static/
>>>
>>> El 10/11/2012, a las 18:22, Markus Unterwaditzer <
>>> markus@unterwaditzer.net> escribió:
>>>
>>> On 2012-11-10 17:39, Norbert Markowicz wrote:
>>>
>>> Hi all,
>>>
>>>
>>> How do I enable flask so that it allows  the .index html
>>>
>>> file access to the files in a particular directory  say:  img
>>>
>>>  (static, templates, img directories are in my main folder)
>>>
>>>
>>> for example when CSS accesses: background:
>>>
>>> url(/img/select-icons.png)
>>>
>>> or standard html access:
>>>
>>>
>>> <a href="img/IMG_0009.JPG'">Click test</a>
>>>
>>>
>>> Thanks in advance
>>>
>>>
>>> It surely would be easiest to use the "static" folder for this. It is
>>> described right in the quickstart:
>>> http://flask.pocoo.org/docs/quickstart/#static-files
>>>
>>>
>>