This project is read-only.

NWSGI - serving static files using wildcard mapping

Dec 28, 2012 at 12:31 PM
Edited Jan 3, 2013 at 9:29 AM

I'm trying to create website using:
    IronPython 2.7.3
    Django 1.4.1
    IIS 7.5
So far everything works fine, except static files.
I tried: " move static files to a separate virtual directory or even separate server that does not use NWSGI.", and still getting 404 error.

ERROR: <title>IIS 7.5 Detailed Error - 404.0 - Not Found</title>

    <wildcard physicalPath="C:\inetpub\wwwroot\project\project\" />
    STATIC_ROOT = 'static'
    STATIC_URL = '/static/'
    urlpatterns = patterns('',
        url(r'^$', 'mysite.views.index'),
        url(r'^project/teststatic', 'mysite.views.teststatic'),
    urlpatterns += staticfiles_urlpatterns()
    def teststatic(request):
        return render_to_response('staticfiletest.html', {}, context_instance=RequestContext(request), mimetype="text/html; charset=utf-8" )


    <!-- <img src="{{ STATIC_URL }}img1.jpg" /> -->
Can someone please help me to solve this ?


Jan 1, 2013 at 2:01 AM

Just wanted to let you know that I have seen this but haven't had a chance to look into it yet. I'll try and dig into it as soon as I can.

Jan 9, 2013 at 9:58 AM

Hi Jeff,
There was a syntax error in my code.
My STATIC_URL should be as /project/static.

Now my textual static files works fine, but images are still broken.
"Unable to translate bytes [FF] at index 0 from specified code page to Unicode."

Jan 9, 2013 at 4:26 PM

I'm glad you figured it out, and I'm sorry for not getting back to you.

Your second problem, I bet, is a Django bug. IronPython's str()s, unlike CPython, are actually Unicode - to properly handle bytes, Django should be using the bytes() type. The stack trace should be able to give you an idea of where the image is being loaded and how, but it will mean digging into the Django code (which is actually quite nice).

Jan 10, 2013 at 11:35 AM
Edited Jan 10, 2013 at 12:07 PM

I've finaly made it!
You were right, there is a bug in Django's
I've simply replaced "response = HttpResponse(, mimetype=mimetype)" with
"response = HttpResponse(bytes(, mimetype=mimetype)", and it works now.

Thanks a lot for the hint, this have bothered me for a long time.

PS: as this is not nwsgi issue maybe this thread should be deleted

Jan 10, 2013 at 4:24 PM

Nah, the thread might still be useful to someone else, so I'll leave it.

If you're got some time you should file an issue with Django. They have no problem taking fixes for IronPython.