Kamilos
Kamilos

Reputation: 805

How can I insert html code from outern url in django template?

I need something like file_get_contents in PHP. I kwnow it's some like:

import urllib2
urllib2.urlopen(url).read()

but how can I put it in django html template?

Thx for fast answers.

Upvotes: 1

Views: 820

Answers (1)

hymloth
hymloth

Reputation: 7045

You cannot put that directly into django's html templating language. You might consider:

  • Prefetching the html, store it somewhere and render it to the template.
  • Use an ajax call, that triggers a view that does the crawling, then on success you insert your html in the DOM (this is blocking and slow at server-side).
  • If you truly want this to be non-blocking, use a non-blocking server. See this code as an example.

Upvotes: 2

Related Questions