External HTML file in Django -
i'm making django app in need embed many external html files in template. each html file stored in own directory, along subdirectory contains images. file structure:
abstract1 pictures image1.png image2.png abstract1.html
i use custom template tag embedding (see below). problem: html files loaded, linked resources (e.g. img) not working (i.e. they're not being displayed). html files use relative urls, which, mixed django template base path produce invalid url, if use hardcoded absolute urls problem remains. feel i'm missing obvious. there proper (or not proper working) way overcome such problem?
template
{% load abstracts_extras %} <!doctype html> <html> <body style="margin-left:10px"> <h2>{{abstract}}</h2> <b>authors:</b><br/> <ul> {% author in authors %} <li>{{author}}</li> {% endfor %} </ul> <p> <b>title: </b>{{abstract.title}} <p> <hr> {% include_external filename|add:'.html' %} </body> </html>
abstracts_extras
from django.template import library register = library() def include_external (url): url = 'file:///' + url import urllib2 return urllib2.urlopen (url).read ()
if understanding well, templates load not statics img. configuration error. should check both settings.py django , httpd.conf apache , check staticfiles configured. have error shown or images not loaded (but no error)?
Comments
Post a Comment