当我硬编码Db详细信息,例如“ connection = cx_Oracle.connect(“ uname/pass@192.168.xxx.yyy:port / db”)“时,我能够成功连接到Oracle Db,但是如何将变量值传递给连接到数据库?
我尝试过这样的事情。
connection = cx_Oracle.connect("{}/{}@{}:{}/{}".format(uname,password,IP,port,db))
它无法正常工作,因此请分享一些想法使其生效。
def knowcobrand(request):
value_type = request.POST.get('CobranSelection')
cobrand_value = request.POST.get('cobrand')
env = request.POST.get('NewEnvName')
print(value_type)
print(cobrand_value)
print(env)
# feed = Environments.objects.get(Q(Env_name__icontains=env))
# print(feed.user_name)
connection = cx_Oracle.connect("app/app@192.168.xxx.yy:port/db")
我想将变量的value_type和env的值用于Db连接
答案 0 :(得分:0)
编辑:您可能应该运行Django tutorial,它将解释Django的基础知识和使用ORM
You should configure your database connection in your settings
There is a specific example for oracle
您现在可以使用Django ORM(after running migrations)
如果您想要数据库的原始游标,您仍然可以像这样使用Django
from django.db import connection
with connection.cursor() as c:
c.execute(...)