Connect Oracle from Django 1.7 (Linux)
Hi, today I'm gonna create new Oracle's related Project with Django 1.7.
My setup is
- Kubuntu 14.10
First thing I will have to have installed oracle-client. You should download these files below from oracle website
- oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
- oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm
- oracle-instantclient12.1-jdbc-12.1.0.2.0-1.x86_64.rpm
- oracle-instantclient12.1-odbc-12.1.0.2.0-1.x86_64.rpm
- oracle-instantclient12.1-tools-12.1.0.2.0-1.x86_64.rpm
- oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm
Then we would use 'alien', which is linux application that can convert rpm to deb. By doing this
>>> sudo alien *.rpm
Then use dpkg install them all
>>> sudo dpkg -i *.deb
Next , edit your bashrc file, by add
export ORACLE_HOME=/usr/lib/oracle/12.1/client64
PATH=$PATH:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
Create virtuaenv or pip to your env
>>> pip install cx_oracle
At this point, you now have an cx_oracle's work (it should), test it by python -c 'import cx_Oracle' then you should get nothing (cool!!).
For Django project, let's edit settings.py, look at DATABASES section
you should try this
DATABASES={
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': 'orcl',
'USER': 'username',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '1521'
}
}
Now, it should work as we want it to have connection R/W to oracle. About detail in depth will come up later :)
Comments
Post a Comment