How to import Django DB operations out of Django projects

i am not familiar with DB opertions. usually i stroe data to txt and other formats. as DB is more and more popular, i want to try it too.

i have some knowledge about Django. the DB opertions in Django is very easy than the DB source code. so i decided to reuse the Django DB operations out of Django projects.

it is very useful for small progress.

import os,sys
sys.path.append('Django project path')
os.environ['DJANGO_SETTINGS_MODULE']='settings'
from .views import viewClasses
import django
django.setup()

All right, we can reuse the Django DB operations for the 'viewClasses' now.

it is practical for basic DB operations like Add / Delete / Update / Retrieve

Hope it can help you.

posted @ 2017-04-18 14:18  frostHIT  阅读(152)  评论(0编辑  收藏  举报