如何在python中为oracle连接传递变量值

问题描述 投票:0回答:1

我能够成功连接到Oracle Db,当我硬编码Db细节,如“connection = cx_Oracle.connect(”uname/[email protected]:port/db“)”但如何传递变量值以连接到D b?

我试过这样的。

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/[email protected]:port/db")

我想使用value_type的变量值和dv连接的env

python django database oracle cx-oracle
1个回答
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(...)
© www.soinside.com 2019 - 2024. All rights reserved.