Use only some parts of Django?

I myself use Django for its object/db mapping without using its urlconfigs. Simply create a file called djangosettings.py and insert the necessary configuration, for example:

DATABASE_ENGINE   = 'oracle'
DATABASE_HOST     = 'localhost'
DATABASE_NAME     = 'ORCL'
DATABASE_USER     = 'scott' 
DATABASE_PASSWORD = 'tiger'

Then in your regular Python code, do

import os
os.environ["DJANGO_SETTINGS_MODULE"] = "djangosettings"

before you import any Django modules. This will let you use Django’s object/db mappings without actually having a Django project, so you can use it for standalone scripts or other web applications or whatever you want.

As for caching, if you don’t want to use Django then you should probably decide what you are using and go from there. I recommend using CherryPy, which doesn’t use Django-style regular expression URL mapping, but instead automatically maps URLs to functions based on the function names. There’s an example right at the top of the CherryPy home page: http://cherrypy.org/

CherryPy has its own caching system, so you can accomplish exactly the same thing as what Django does but without needing to use Django’s urlconfig system.

Leave a Comment