I was having a problem printing Youtube’s Unicode data using my print method:
print "<p>Video: desc=%s</p>" % (vid.desc)
I’m not well versed with Unicode data, so I was just able to brute force out of this problem, and get rid of the UnicodeDecodeError “ordinal out of range”, by doing the following:
print "<p>Video: desc=%s</p>" % (unicode(vid.desc,'iso-8859-1'))
PS: My database information is in utf-8 format. So, in my understanding, this is converting that utf-8 data into iso-8859-1 to show to the users.
Getting the following when trying to use MySQLdb in virtualenv’s django:
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
Activate and Run:
pip install MySQLdb
Django on centos geekymedia
for setuptools (easy_install):
use it to install pip:
download MySQLdb and install by:
python26 setup.py build
python26 setup.py install
add to .bashrc
Start virtualenv for current session
now install packages, they will go inside virtualenv (since we are activated)
pip install django
pip install south
pip install pil
Create django project and app
django-admin.py startproject myproj
python manage.py startapp polls
When I created a Django application, I hadn’t noticed that my MySQL was defaulted to latin character set (probably by Virtualmin or CentOS’s default MySQL values). So I didn’t want to delete my current project and start again. So here are the commands to convert a database to unicode:
for the database
ALTER DATABASE djangodb CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci
on each table do
ALTER TABLE djangotablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci
Started receiving this error after I pasted some template code from a WordPress blog (it could also happen from any word processing product like Microsoft Office’s MS Word). The solution to this problem was that I had to look through my code to hunt down the following characters and replace them with their equivalents:
” ‘ ’
Replaced with (respectively):
" ' '
This is probably a very rare error that one may encounter in Django. But I think I should share it here, as it would save about an hour of anybody else who has this problem.
Exception Type: ImproperlyConfigured at /
Error importing authentication backend
I was very desparate to change the name of an app inside my Django project. I renamed the folder name and all possible mentions of the application name anywhere in the code and the database tables (Please note: This is not recommended, there is probably a better solution to do this). Once I faced that problem with no clear indication of where I was going wrong, I looked everywhere in the code and the database. After going into panic mode, I tried desperately changing and removing anything that may break. In the end, I ran out of places to find the application name but the error still existed.
I had noticed after looking at my cookies that I still had cookies from my session, which meant that everytime I connected to the server, I was trying to pass my “delicious” cookies. But just deleting your own cookies won’t do it. The session object of the user was cached in the database inside the table “django_session”. This especially stores the “AUTHENTICATION_BACKENDS” last used. So, truncate the table:
TRUNCATE TABLE django_session to finally get rid of this nasty problem.