How to run Django v1.1 project in Django v1.4 environment

Yes, that's it!!! I know this is one of the most annoying things you've ever met when develop Django app, framework upgrading.
The first time I saw an Django application, it was Django v1.1.1. I tried to run the source code in Django 1.4.2 environment (inside virtualenv), but It becamed a mess. So, I quitted and decided to continue running the project in the shitty old v1.1 of Django.

After more than 3 months, I finally figured out how to migrate the source code to the new environment.Rule number 1: read the release notes carefully. compare it with the old django environment and you will see where to begin

(https://docs.djangoproject.com/en/dev/releases/1.4/)
 Step 1: Change or add the following settings in settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'dbname', 
'USER': 'dbuser', 
'PASSWORD': 'dbpassword', 
'HOST': '', 
'PORT': '', 
}
}

TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader', 
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)

STATIC_ROOT = "/absolute/path/to/media/"
STATIC_URL = "/url/of/site_media/"

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
)
Step 2:  Add the csrf_token tag to after every form in templates: {% csrf_token %}
Step 3: Add the decoration @csrf_exempt to before every view that serve ajax request

If your Django app still cannot run properly, read the release notes carefully again and check the debug output of the app, you will find the light!
Pretty cool huh?
Trinh 



- updates Jan 10, 2013: In Django 1.4 dont use as following when dealing with inlineformset:
for form in your_inlineformset:
      form.save()
use this instead:

your_inlineformset.save()






Comments