How to show python data on html

99 views
Skip to first unread message

123asror

unread,
Feb 7, 2016, 8:07:52 AM2/7/16
to Django users
So currently i have a python console application that reads from an api and print some data i want. I followed the django course and they use models/database in it. The data that they show comes from that. So i was wondering how to add a html page to my console application or python code. Is there a tutorial i can follow for that ?

Omar Abou Mrad

unread,
Feb 8, 2016, 3:19:31 AM2/8/16
to django...@googlegroups.com
On Sun, Feb 7, 2016 at 11:15 AM, 123asror <asror...@gmail.com> wrote:
So currently i have a python console application that reads from an api and print some data i want. I followed the django course and they use models/database in it. The data that they show comes from that. So i was wondering how to add a html page to my console application or python code. Is there a tutorial i can follow for that ?

- Do you just want to save the data you're receiving in an HTML file?

If so, you're better off just using a template library (jinja or other), there's no need for an entire framework to do this.

- Do you want to serve the data so that it's accessible through a browser?

If so, then yes you could use django for this purpose. Django isn't limited to fetching data from the database, it's primary job is to enable you to serve content. You have content, you want to deliver this content, django is for you.

- Is your console application short running? Does it do it's job, print the content and then exit?

If so, you can just invoke the application from within a django view. However, if the operation isn't very fast, you may want to reach out to a task queue, but you really should worry about this in due time.

- Is your console application long running? Does it fetch data constantly?

Then you'll need to decide on how to make content available for your django application to serve. One of the ways you could do this is have your application send the data to a medium and have django read from that medium. Possibly store in files, in the database, in a queue or some other place, then django could read from there.

- Do you plan on delivering the content in realtime as you receive it?

If so, I'd suggest placing this as a different phase of implementation, but some keywords for you to look for if you ever get to that point: javascript polling, websockets, tornado, gevent, socket.io...

-

Good luck.


Derek

unread,
Feb 8, 2016, 9:24:14 AM2/8/16
to Django users
Depending on what your console app does or needs to do, you can also look at Flask as a way of serving up HTML pages to your browser; see http://flask.pocoo.org/docs/0.10/quickstart/  - you then do not have to use a database with models if those are not needed.  Django is great but not always appropriate.

Luis Zárate

unread,
Feb 8, 2016, 6:40:34 PM2/8/16
to django...@googlegroups.com
Database models approuch only the most popular form of manipulate data, but django is MVT so you could have different representation of the "M" (eg. External API) and full use of "VT".
An example.

def myfunc(request):
     mydata = my_dict_get_by_api_call()
     return render(request, 'template.html', mydata)

Suppose that mydata has 'myobj' as a key  so in template.html you can do

{{myobj}}

Of course you could use URLs to access your view :)
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/548519fc-c84a-4733-8b71-e371aa62dc11%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

--
"La utopía sirve para caminar" Fernando Birri



Reply all
Reply to author
Forward
0 new messages