librelist archives

« back to archive

flask and existing python code...

flask and existing python code...

From:
arief nur andono
Date:
2011-02-23 @ 05:36
Hi, please someone give me some advice to combine flask with existing python
code

because I want to combine flask with standard python code like in
http://geospatialpython.com/
so flask as front-end and call my standard code that convert shp to jpg then
return flask the image filename
so flask could display it on the web,,,,

what should I do to make it work??

Re: [flask] flask and existing python code...

From:
Ishbir Singh
Date:
2011-02-23 @ 08:16
Hey,

Flask itself is implemented in Python. In your views, simply add the
processing code to get it to work.

Eg. In your view-

def convert():
    file = request.form['file']
    new_filename = ConvertToJpg(file.read(), save_location)
    return 'Done, new filename is', new_filename

ConvertToJpg is an arbitary function here.

On Wed, Feb 23, 2011 at 11:06 AM, arief nur andono <ariefnurandono@gmail.com
> wrote:

> Hi, please someone give me some advice to combine flask with existing
> python code
>
> because I want to combine flask with standard python code like in
> http://geospatialpython.com/
> so flask as front-end and call my standard code that convert shp to jpg
> then return flask the image filename
> so flask could display it on the web,,,,
>
> what should I do to make it work??
>
>


-- 
Ishbir Singh

Re: [flask] flask and existing python code...

From:
arief nur andono
Date:
2011-02-24 @ 03:01
thanks for the respons

can't I create in different file??
because it will make the views looks more complex than it should
the flask simplicity would just lost if I put all python code in views

2011/2/23 Ishbir Singh <ishbir24@gmail.com>

> Hey,
>
> Flask itself is implemented in Python. In your views, simply add the
> processing code to get it to work.
>
> Eg. In your view-
>
> def convert():
>     file = request.form['file']
>     new_filename = ConvertToJpg(file.read(), save_location)
>     return 'Done, new filename is', new_filename
>
> ConvertToJpg is an arbitary function here.
>
>
> On Wed, Feb 23, 2011 at 11:06 AM, arief nur andono <
> ariefnurandono@gmail.com> wrote:
>
>> Hi, please someone give me some advice to combine flask with existing
>> python code
>>
>> because I want to combine flask with standard python code like in
>> http://geospatialpython.com/
>> so flask as front-end and call my standard code that convert shp to jpg
>> then return flask the image filename
>> so flask could display it on the web,,,,
>>
>> what should I do to make it work??
>>
>>
>
>
> --
> Ishbir Singh
>

Re: [flask] flask and existing python code...

From:
Ishbir Singh
Date:
2011-02-24 @ 10:53
Hey,

Obviously, you could. Just import it. Say you have a modules folder and in
it a file called operations.py containing 'ConvertFile' function, do so
something like this-

from application.modules.operations import ConvertFile

In your view function, simply call the ConvertFile function.

On Thu, Feb 24, 2011 at 8:31 AM, arief nur andono
<ariefnurandono@gmail.com>wrote:

> thanks for the respons
>
> can't I create in different file??
> because it will make the views looks more complex than it should
> the flask simplicity would just lost if I put all python code in views
>
> 2011/2/23 Ishbir Singh <ishbir24@gmail.com>
>
> Hey,
>>
>> Flask itself is implemented in Python. In your views, simply add the
>> processing code to get it to work.
>>
>> Eg. In your view-
>>
>> def convert():
>>     file = request.form['file']
>>     new_filename = ConvertToJpg(file.read(), save_location)
>>     return 'Done, new filename is', new_filename
>>
>> ConvertToJpg is an arbitary function here.
>>
>>
>> On Wed, Feb 23, 2011 at 11:06 AM, arief nur andono <
>> ariefnurandono@gmail.com> wrote:
>>
>>> Hi, please someone give me some advice to combine flask with existing
>>> python code
>>>
>>> because I want to combine flask with standard python code like in
>>> http://geospatialpython.com/
>>> so flask as front-end and call my standard code that convert shp to jpg
>>> then return flask the image filename
>>> so flask could display it on the web,,,,
>>>
>>> what should I do to make it work??
>>>
>>>
>>
>>
>> --
>> Ishbir Singh
>>
>
>


-- 
Ishbir Singh