Saturday, September 27, 2014

Re: Rendering XML using XSLT

Some details I forgot are that this is Django 1.6.4, Python 3.4.1.

On Sat, Sep 27, 2014 at 8:10 AM, Timothy W. Cook <> wrote:
I have a view that opens an XML file (it happens to be a schema but that doesn't matter) that specifies a stylesheet.
It works as expected when opening the XML file locally.

​The stylesheet isn't applied when viewing the file via Django and I see in Firebug that I am getting a 404 on the stylesheet. The stylesheet is in the same directory as the XML file.

So how do I setup a view or add this file to my existing view so it is found? 

The view:
def get_ccddetails(request, id):

    ccd = CCD.objects.get(pk=id)
    ccdid= ccd.ct_id

    CWD = os.getcwd()
    if CWD == '/':    # Live site
        frm_dir = "/home/ccdgen/ccdlib/CCD_"+ ccdid
    else:             # development
        frm_dir = "ccdlib/CCD_"+ ccdid

    filename = frm_dir+"/ccd-"+ccdid+".xsd"
    if os.path.isfile(filename):
        response = HttpResponse(mimetype="application/xml; charset=utf-8")
        f = open(filename, encoding="utf-8")
        for line in f:
        response = HttpResponseNotFound("<h1>XSD: "+filename+" was not found.</h1>")
    return response

​The URL:
​    url(r'^get_xsd/(?P<id>\d+)$', "ccdgen.views.get_ccddetails", name='getxsd'),



Timothy Cook
LinkedIn Profile:


Timothy Cook
LinkedIn Profile:

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
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment