PyCharm + Django runserver “Inappropriate ioctl for device” error

While I am by no means opposed to coding in a text editor such as TextMate, the convenience of an IDE with code-completion & integrated debugging is always a preferred option when available. I’ve been doing all my Django development in TextMate and a command prompt and it’s by no means painful, but there are some repetitive actions that could be simplified, and code-completion would make things so much faster. I’m vehemently opposed to Eclipse even though a myriad of developers out there swear by it, but I came across PyCharm from JetBrains over the weekend and it’s actually pretty damn nice… BUT using the integrated manage.py command for runserver was failing with:

termios.error: (25, 'Inappropriate ioctl for device')

I saw this referenced in a few posts around the web but none of them put together a single defined solution to the problem, so here’s what I ended up having to do. Supposedly JetBrains even made a workaround in a PyCharm release several releases ago, but it still wasn’t working for me using Django 1.3 and PyCharm 1.5.  You have to modify one of the files in your django install, which for me was in my system python site-packages directory. Here’s the specific patch you have to apply.