librelist archives

« back to archive

Reading data from file and displaying it on browser

Reading data from file and displaying it on browser

From:
jamal sasha
Date:
2013-02-07 @ 02:53
Hi,
 I am trying out something very simple.

I have a file  on local disk and I want to read data from this file and
display its contents on browser.
How do i do this in flask?
Thanks
Jamal

Re: [flask] Reading data from file and displaying it on browser

From:
Steven Kryskalla
Date:
2013-02-07 @ 02:58
On Wed, Feb 6, 2013 at 6:53 PM, jamal sasha <jamalshasha@gmail.com> wrote:
> I have a file  on local disk and I want to read data from this file and
> display its contents on browser.
> How do i do this in flask?

Try this:
http://flask.pocoo.org/docs/api/#flask.send_file

Re: [flask] Reading data from file and displaying it on browser

From:
jamal sasha
Date:
2013-02-07 @ 03:32
Hi Steven,
  Thanks for quick reply.
I am having hard time gluing python with the webby part..


I followed this tutorial to help me get started:

http://net.tutsplus.com/tutorials/python-tutorials/an-introduction-to-pythons-flask-framework/

But in the "Welcome to Flask app" area in the final snap shot.
I want to read contents from a file in a local disk and display it on that
area?
I would really really apperciate if someone can help me get started..
Thanks




On Wed, Feb 6, 2013 at 6:58 PM, Steven Kryskalla <skryskalla@gmail.com>wrote:

> On Wed, Feb 6, 2013 at 6:53 PM, jamal sasha <jamalshasha@gmail.com> wrote:
> > I have a file  on local disk and I want to read data from this file and
> > display its contents on browser.
> > How do i do this in flask?
>
> Try this:
> http://flask.pocoo.org/docs/api/#flask.send_file
>

Re: [flask] Reading data from file and displaying it on browser

From:
anh le
Date:
2013-02-07 @ 04:17
Hi,

Is this what you are probably looking for?

# app.py

from flask import Flask, Markup

app = Flask(__name__)

@app.route('/')
def index():
    """ Return content of this file itself"""
    this_source = open(__file__).read()
    return "<pre>%s</pre>" % Markup.escape(this_source)

if __name__ == '__main__':
    app.run(debug=True)

you can open  your own file instead of __file__, and I just wrap the
content around <pre>
so that it displays the source nicely.  Also consider using render_template.


On Thu, Feb 7, 2013 at 10:32 AM, jamal sasha <jamalshasha@gmail.com> wrote:
> Hi Steven,
>   Thanks for quick reply.
> I am having hard time gluing python with the webby part..
>
>
> I followed this tutorial to help me get started:
> 
http://net.tutsplus.com/tutorials/python-tutorials/an-introduction-to-pythons-flask-framework/
>
> But in the "Welcome to Flask app" area in the final snap shot.
> I want to read contents from a file in a local disk and display it on that
> area?
> I would really really apperciate if someone can help me get started..
> Thanks
>
>
>
>
> On Wed, Feb 6, 2013 at 6:58 PM, Steven Kryskalla <skryskalla@gmail.com>
> wrote:
>>
>> On Wed, Feb 6, 2013 at 6:53 PM, jamal sasha <jamalshasha@gmail.com> wrote:
>> > I have a file  on local disk and I want to read data from this file and
>> > display its contents on browser.
>> > How do i do this in flask?
>>
>> Try this:
>> http://flask.pocoo.org/docs/api/#flask.send_file
>
>

Re: [flask] Reading data from file and displaying it on browser

From:
jamal sasha
Date:
2013-02-07 @ 04:33
:) yes. yes.. this does the job..
Just out of curosity.. how would I use render template here?
Thanks for all the help


On Wed, Feb 6, 2013 at 8:17 PM, anh le <anhlh2@gmail.com> wrote:

> Hi,
>
> Is this what you are probably looking for?
>
> # app.py
>
> from flask import Flask, Markup
>
> app = Flask(__name__)
>
> @app.route('/')
> def index():
>     """ Return content of this file itself"""
>     this_source = open(__file__).read()
>     return "<pre>%s</pre>" % Markup.escape(this_source)
>
> if __name__ == '__main__':
>     app.run(debug=True)
>
> you can open  your own file instead of __file__, and I just wrap the
> content around <pre>
> so that it displays the source nicely.  Also consider using
> render_template.
>
>
> On Thu, Feb 7, 2013 at 10:32 AM, jamal sasha <jamalshasha@gmail.com>
> wrote:
> > Hi Steven,
> >   Thanks for quick reply.
> > I am having hard time gluing python with the webby part..
> >
> >
> > I followed this tutorial to help me get started:
> >
> 
http://net.tutsplus.com/tutorials/python-tutorials/an-introduction-to-pythons-flask-framework/
> >
> > But in the "Welcome to Flask app" area in the final snap shot.
> > I want to read contents from a file in a local disk and display it on
> that
> > area?
> > I would really really apperciate if someone can help me get started..
> > Thanks
> >
> >
> >
> >
> > On Wed, Feb 6, 2013 at 6:58 PM, Steven Kryskalla <skryskalla@gmail.com>
> > wrote:
> >>
> >> On Wed, Feb 6, 2013 at 6:53 PM, jamal sasha <jamalshasha@gmail.com>
> wrote:
> >> > I have a file  on local disk and I want to read data from this file
> and
> >> > display its contents on browser.
> >> > How do i do this in flask?
> >>
> >> Try this:
> >> http://flask.pocoo.org/docs/api/#flask.send_file
> >
> >
>

Re: [flask] Reading data from file and displaying it on browser

From:
Steven Kryskalla
Date:
2013-02-07 @ 06:09
On Wed, Feb 6, 2013 at 8:33 PM, jamal sasha <jamalshasha@gmail.com> wrote:
> :) yes. yes.. this does the job..
> Just out of curosity.. how would I use render template here?
> Thanks for all the help

Just pass the contents of the file into the template:

contents = open("file.txt").read()
return render_template("something.html", contents=contents)

Then in your template:

{{contents}}

Re: [flask] Reading data from file and displaying it on browser

From:
jamal sasha
Date:
2013-02-07 @ 06:38
Thank you so much Steven.
I can't thank you enough.
I had almost given up on this :)


On Wed, Feb 6, 2013 at 10:09 PM, Steven Kryskalla <skryskalla@gmail.com>wrote:

> On Wed, Feb 6, 2013 at 8:33 PM, jamal sasha <jamalshasha@gmail.com> wrote:
> > :) yes. yes.. this does the job..
> > Just out of curosity.. how would I use render template here?
> > Thanks for all the help
>
> Just pass the contents of the file into the template:
>
> contents = open("file.txt").read()
> return render_template("something.html", contents=contents)
>
> Then in your template:
>
> {{contents}}
>

Re: [flask] Reading data from file and displaying it on browser

From:
jamal sasha
Date:
2013-02-07 @ 06:49
and also toh anh le :)


On Wed, Feb 6, 2013 at 10:38 PM, jamal sasha <jamalshasha@gmail.com> wrote:

> Thank you so much Steven.
> I can't thank you enough.
> I had almost given up on this :)
>
>
> On Wed, Feb 6, 2013 at 10:09 PM, Steven Kryskalla <skryskalla@gmail.com>wrote:
>
>> On Wed, Feb 6, 2013 at 8:33 PM, jamal sasha <jamalshasha@gmail.com>
>> wrote:
>> > :) yes. yes.. this does the job..
>> > Just out of curosity.. how would I use render template here?
>> > Thanks for all the help
>>
>> Just pass the contents of the file into the template:
>>
>> contents = open("file.txt").read()
>> return render_template("something.html", contents=contents)
>>
>> Then in your template:
>>
>> {{contents}}
>>
>
>

Re: [flask] Reading data from file and displaying it on browser

From:
Steven Kryskalla
Date:
2013-02-07 @ 06:51
On Wed, Feb 6, 2013 at 10:38 PM, jamal sasha <jamalshasha@gmail.com> wrote:
> Thank you so much Steven.
> I can't thank you enough.
> I had almost given up on this :)

Don't give up! If you're getting stuck on something in flask I
recommend learning the python basics a bit more. These are all good
resources for beginners:

http://learnpythonthehardway.org/book/
https://developers.google.com/edu/python/ (also has really good videos
on youtube)
http://docs.python.org/2/tutorial/index.html
http://www.diveintopython.net/toc/index.html

best,
Steve

Re: [flask] Reading data from file and displaying it on browser

From:
jamal sasha
Date:
2013-02-07 @ 07:26
Oh. Actually python is not an issue. I wanted to start with flask because
of python only..
But my limitation is the webish technologies.. :(

But you guys have helped me to stuck my foot in the door..
on how can i manipulate everything on python and end and then a basic
template to render it on html :)


On Wed, Feb 6, 2013 at 10:51 PM, Steven Kryskalla <skryskalla@gmail.com>wrote:

> On Wed, Feb 6, 2013 at 10:38 PM, jamal sasha <jamalshasha@gmail.com>
> wrote:
> > Thank you so much Steven.
> > I can't thank you enough.
> > I had almost given up on this :)
>
> Don't give up! If you're getting stuck on something in flask I
> recommend learning the python basics a bit more. These are all good
> resources for beginners:
>
> http://learnpythonthehardway.org/book/
> https://developers.google.com/edu/python/ (also has really good videos
> on youtube)
> http://docs.python.org/2/tutorial/index.html
> http://www.diveintopython.net/toc/index.html
>
> best,
> Steve
>

Re: [flask] Reading data from file and displaying it on browser

From:
Nathan M
Date:
2013-02-07 @ 09:08
If python is not the issue, do read the flask doc, it's great!
Le 7 févr. 2013 08:39, "jamal sasha" <jamalshasha@gmail.com> a écrit :

> Oh. Actually python is not an issue. I wanted to start with flask because
> of python only..
> But my limitation is the webish technologies.. :(
>
> But you guys have helped me to stuck my foot in the door..
> on how can i manipulate everything on python and end and then a basic
> template to render it on html :)
>
>
> On Wed, Feb 6, 2013 at 10:51 PM, Steven Kryskalla <skryskalla@gmail.com>wrote:
>
>> On Wed, Feb 6, 2013 at 10:38 PM, jamal sasha <jamalshasha@gmail.com>
>> wrote:
>> > Thank you so much Steven.
>> > I can't thank you enough.
>> > I had almost given up on this :)
>>
>> Don't give up! If you're getting stuck on something in flask I
>> recommend learning the python basics a bit more. These are all good
>> resources for beginners:
>>
>> http://learnpythonthehardway.org/book/
>> https://developers.google.com/edu/python/ (also has really good videos
>> on youtube)
>> http://docs.python.org/2/tutorial/index.html
>> http://www.diveintopython.net/toc/index.html
>>
>> best,
>> Steve
>>
>
>

Re: [flask] Reading data from file and displaying it on browser

From:
Owein Reese
Date:
2013-02-08 @ 00:46
Or look up hacker groups in your area. NYC has weekly office hours with
tons of helpful people.
On Feb 7, 2013 4:15 AM, "Nathan M" <feydaykyn@gmail.com> wrote:

> If python is not the issue, do read the flask doc, it's great!
> Le 7 févr. 2013 08:39, "jamal sasha" <jamalshasha@gmail.com> a écrit :
>
>> Oh. Actually python is not an issue. I wanted to start with flask because
>> of python only..
>> But my limitation is the webish technologies.. :(
>>
>> But you guys have helped me to stuck my foot in the door..
>> on how can i manipulate everything on python and end and then a basic
>> template to render it on html :)
>>
>>
>> On Wed, Feb 6, 2013 at 10:51 PM, Steven Kryskalla <skryskalla@gmail.com>wrote:
>>
>>> On Wed, Feb 6, 2013 at 10:38 PM, jamal sasha <jamalshasha@gmail.com>
>>> wrote:
>>> > Thank you so much Steven.
>>> > I can't thank you enough.
>>> > I had almost given up on this :)
>>>
>>> Don't give up! If you're getting stuck on something in flask I
>>> recommend learning the python basics a bit more. These are all good
>>> resources for beginners:
>>>
>>> http://learnpythonthehardway.org/book/
>>> https://developers.google.com/edu/python/ (also has really good videos
>>> on youtube)
>>> http://docs.python.org/2/tutorial/index.html
>>> http://www.diveintopython.net/toc/index.html
>>>
>>> best,
>>> Steve
>>>
>>
>>