專欄目錄
專欄詳情
Django動態調用模型ORM類
from django.apps import apps as django_apps
appname = 'App Name'
orm = dict([(x._meta.db_table, x) for x in django_apps.get_config(appname).get_models()])
orm.get('table_name')
複製代碼
Django-Request參數對象不可修改
request.data._mutable = True
複製代碼
腳本中添加Django項目環境
import os
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "DjangoOBJName.settings")
django.setup()
import sys
sys.path.append("Django-Object-Path")
os.environ['DJANGO_SETTINGS_MODULE'] = 'DjangoOBJName.settings'
複製代碼