我有一个代码可以列出数据库中所有数据到下拉列表
def makeDictFactory(cursor):
columnNames = [d[0] for d in cursor.description]
def createRow(*args):
return dict(zip(columnNames,args))
return createRow
def list_all_table(request):
import cx_Oracle
dsn_tns = cx_Oracle.makedsn('','',sid='')
conn = cx_Oracle.connect(user=r'',password='',dsn=dsn_tns)
c = conn.cursor()
c.execute("select table_name from all_tables")
c.rowfactory = makeDictFactory(c)
for rowDict in c:
context = {
'obj2':rowDict
}
#database_table = c.fetchall()
return render(request,'define_segment.html',context)
这是html代码
<div class="btn-group">
<select style="width:425px;background-color:white;height:30px;font-color:red;text-align-last:center;">
{% for table in obj2 %}
<option>{{ table.table_name }}</option>
{% endfor %}
</select>
</div>
如何将参数传递给HTML中的obj2,我觉得我的观点是错误的,我需要帮助修复它,谢谢
P.S:我需要此views.py
才能从此代码中进行依赖下拉