Sodalum:
example.py
Code: Alles auswählen
#!/usr/bin/env
# -*- coding: utf-8 -*-
# mal eben auf die schnelle unerhörte imports...
from bottle import *
import urllib2
import cookielib
import json
@route('/')
def start():
cj = cookielib.LWPCookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
opener.addheaders = [('User-agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10')]
url = "http://www.imdbapi.com/?i=tt0133093"
html = opener.open(url).read()
jdata = json.loads(html)
imdbid = jdata["imdbID"]
title = jdata["Title"]
image = jdata["Poster"]
return template('details', imdbid=imdbid, title=title, image=image)
debug(True)
run(host='localhost', port='8080', reloader=True)
views/details.tpl
Code: Alles auswählen
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>foobar</title>
</head>
<body>
<hr>
<p>
IMDBID: {{imdbid}}<br>
Title: {{title}}<br>
<img src="{{image}}" alt="load image" width="214px" height="317px" /><br>
</p>
<hr>
</body>
</html>
Bevor nun alle schreien also bei mir geht das, noch:
Es funktioniert lokal.
Als Server benutze ich einen Apache mit mod_wsgi.
Symptom: Bild online nicht da, alles andere schon.
Lädt man das Bild in einem anderen Tab und die Seite auf der es angezeigt werden soll neu, dann auch dort...
Danke für euere Anteilnahme.