librelist archives

« back to archive

Another fileformats in Flask

Another fileformats in Flask

From:
Mikko Koho
Date:
2015-03-31 @ 11:28
Hello

Flask seems to be solution to my problem but still I have one. I will have
a file, for example "trend.py", which contains code which produces
trendgraph(s) from online-information made by my Python-project. But, when
it returns an variable which constain content of svg-file, I can only
produce file named "trend.svg.html". How can I make files which only
contains name "trend.svg" and then browser understands that it is an
svg-file, not html-file.

Or is it right way to do this solution?

Mikko

Re: [flask] Another fileformats in Flask

From:
Felipe Barreto Volpone
Date:
2015-03-31 @ 12:06
Hey Mikko, have you already tried  change the content-type/mimetype of the
response?
Something like this:

from flask import Response
@app.route('/your_url')
def render_grap():
    graph_svg = ....
    return Response(graph_svg, mimetype='image/svg+xml')

2015-03-31 8:28 GMT-03:00 Mikko Koho <cryogenium@gmail.com>:

> Hello
>
> Flask seems to be solution to my problem but still I have one. I will have
> a file, for example "trend.py", which contains code which produces
> trendgraph(s) from online-information made by my Python-project. But, when
> it returns an variable which constain content of svg-file, I can only
> produce file named "trend.svg.html". How can I make files which only
> contains name "trend.svg" and then browser understands that it is an
> svg-file, not html-file.
>
> Or is it right way to do this solution?
>
> Mikko
>

Re: [flask] Another fileformats in Flask

From:
Mikko Koho
Date:
2015-03-31 @ 18:45
Thank you very much! Works very well, in Finland we said "works like toilet
on the train" until we got new trains..

Mikko

2015-03-31 15:06 GMT+03:00 Felipe Barreto Volpone <felipevolpone@gmail.com>:

> Hey Mikko, have you already tried  change the content-type/mimetype of the
> response?
> Something like this:
>
> from flask import Response
> @app.route('/your_url')
> def render_grap():
>     graph_svg = ....
>     return Response(graph_svg, mimetype='image/svg+xml')
>
> 2015-03-31 8:28 GMT-03:00 Mikko Koho <cryogenium@gmail.com>:
>
>> Hello
>>
>> Flask seems to be solution to my problem but still I have one. I will
>> have a file, for example "trend.py", which contains code which produces
>> trendgraph(s) from online-information made by my Python-project. But, when
>> it returns an variable which c onstain content of svg-file, I can only
>> produce file named "trend.svg.html". How can I make files which only
>> contains name "trend.svg" and then browser understands that it is an
>> svg-file, not html-file.
>>
>> Or is it right way to do this solution?
>>
>> Mikko
>>
>
>

Re: [flask] Another fileformats in Flask

From:
Felipe Barreto Volpone
Date:
2015-03-31 @ 20:23
hahaha great!

2015-03-31 15:45 GMT-03:00 Mikko Koho <cryogenium@gmail.com>:

> Thank you very much! Works very well, in Finland we said "works like
> toilet on the train" until we got new trains..
>
> Mikko
>
> 2015-03-31 15:06 GMT+03:00 Felipe Barreto Volpone <felipevolpone@gmail.com
> >:
>
>> Hey Mikko, have you already tried  change the content-type/mimetype of
>> the response?
>> Something like this:
>>
>> from flask import Response
>> @app.route('/your_url')
>> def render_grap():
>>     graph_svg = ....
>>     return Response(graph_svg, mimetype='image/svg+xml')
>>
>> 2015-03-31 8:28 GMT-03:00 Mikko Koho <cryogenium@gmail.com>:
>>
>>> Hello
>>>
>>> Flask seems to be solution to my problem but still I have one. I will
>>> have a file, for example "trend.py", which contains code which produces
>>> trendgraph(s) from online-information made by my Python-project. But, when
>>> it returns an variable which c onstain content of svg-file, I can only
>>> produce file named "trend.svg.html". How can I make files which only
>>> contains name "trend.svg" and then browser understands that it is an
>>> svg-file, not html-file.
>>>
>>> Or is it right way to do this solution?
>>>
>>> Mikko
>>>
>>
>>
>