The hosting company I’m working through has some old versions of various frameworks installed, and won’t update them for various reasons, which is a bit annoying, but I think some of the reasons are valid (breaking other management applications). Ruby on Rails changes frequently, and I don’t think the support and documentation are really where they should be. I had several false starts trying to get some RoR applications running on this webhost, and spent more time trying to solve the various problems that came up than actually writing script code. A friend in DC suggested that I try Python and Django instead; it was more stable, better supported, and in the case of Python, saw more widespread application in professional and even academic settings. There was a Python class offered I think my senior year of college, but it didn’t fit into my schedule, and unfortunately, wasn’t recorded for the campus video network.
In any case, some relatively recent versions of Python and Django are present, and I’ve been able to solve problems that have come up with a bit of searching. The base of knowledge is pretty broad, so I’ve been able to look through a few different similar issues for each problem I’ve had.
First, some background: the server is running Apache, and Python (2.4.3) is accessible via mod_python, and I’m using Django (v1.2) on top of that. Following this tutorial, which is way more detailed than the equivalent for RoR, I didn’t actually run into problems until I hit part 2 because the stylesheets and other media for the admin app are located within the Django installation location, not my local user account. I had also setup a subdomain to view the site, since it’s a shared host and 127.0.0.1:8000 isn’t accessible remotely. Originally, I was following this tutorial, which is mostly correct, but I believe it was written for even a pre-1.0 version of Django, so not entirely accurate. Errors so far:
- The file permissions on the SQLite database file shoudl be at least 0666 (+rw), but the permissions for the django-code folder and all folders within need to be at least 0755 (+x). mod_python was giving errors about not being able to find my settings.py file when this wasn’t present:
ImportError: Could not import settings 'mysite.settings' (Is it on sys.path? Does it have syntax errors?): No module named mysite.settings
If the database is not writable by group and others, you get a predictable error:
DatabaseError: attempt to write a readonly database
- The .htaccess file PythonPath entry should include not only your Django code folder, but also the absolute path to your project, for example:
PythonPath "['/home/USER/django-code/', '/home/USER/django-code/mysite/'] + sys.path"
mod_python was giving errors about not being able to find application modules within my project without it:
TemplateSyntaxError: Caught ImportError while rendering: No module named myapp
- The admin app bundled with Django has some media associated with it that won’t load, since I’m working in
/home/USER/django-code/mysite, whereas the admin media resides at
/usr/lib/python2.4/site-packages/django/contrib/admin/media/. Solved this problem by just copying the files to
~/public_html/static, and making a symbolic link, static, from my subdomain folder to the public_html copy. I couldn’t just make a symlink to the
/usr/lib/...copy because of permission problems.
- Doing anything with the admin app gives me an error that I think is related to the Python and Django versions being used:
File "/usr/lib64/python2.4/hmac.py", line 42, in __init__
self.outer = digestmod.new()
AttributeError: 'builtin_function_or_method' object has no attribute 'new'
I only just discovered it, and haven’t found a workaround yet.