@ wrote... (4 years, 10 months ago)

Sometimes you don't have a favicon.ico or it's not in your staticfiles because you have a single page javascript or you're just tired of seeing 404s in your debug output.

Here's how you can serve up a hard coded icon (or any file really) directly from django.

I got this transparent icon from transparent-favicon.info

wget http://transparent-favicon.info/favicon.ico
base64 favicon.ico

I put this in my main project urls.py but feel free to put wherever.

# project/urls.py

def favicon(request):
    from textwrap import dedent
    from django.http import HttpResponse
    import base64

    icon = """\
    AAABAAEAEBACAAEAAQCwAAAAFgAAACgAAAAQAAAAIAAAAAEAAQAAAAAAgAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAA////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD/
    /wAA//8AAP//AAD//wAA//8AAP//AAD//wAA"""
    icon = dedent(icon)
    icon = base64.b64decode(icon)

    return HttpResponse(icon, content_type="image/x-icon")

urlpatterns += [
    url(r'^favicon.ico', favicon, name='favicon'),
]
Category: tech, Tags: django
Comments: 0
@ wrote... (9 years, 7 months ago)

OMG I HATE MY LIFE SOMETIMES

So… I'll hopefully write more about this later, but the TL;DR is do not use monitor.py and uwsgi.

So if you have something like this in your wsgi.py, comment it out with extreme prejudice.

import monitor
monitor.start(interval=60)

Symptoms include, but not limited to:

  • workers not shutting down
  • workers appear to hang and cause 50x errors
  • workers not restarting if you send appropriate signals
  • workers appear to work once or twice then hang
  • workers never work
  • randomness and non-determinism all over the f'in place
  • little to no helpful log output
  • propensity to start adding lots of config variables that you don't understand
  • propensity to start drinking
  • wondering htf everybody else seems to use this software without a problem
  • wondering if perhaps computers where a poor career choice after all

I haven't looked into too closely but I suspect the fact that the monitor opens up it's own thread and runs forever has something to do with it. Open files, open sockets, stuff like that.

Category: tech, Tags: django, linux, nginx
Comments: 0
@ wrote... (10 years, 6 months ago)

Django works much better if you do things the right way. Here are the steps for future me.

more…

Category: tech, Tags: django
Comments: 0