0

select *from table_name where name = %s",params={"name1","name2"}

全码:

from django.shortcuts import render
from . models import destination

def index(request,params = None):       
  dests1 = destination.objects.raw("select *from travello_destination where name = %s",params={'Bangalore','Mumbai'})
  return render(request,'index.html', {"dests":dests1})
4

1 回答 1

0

您错误地使用了原始查询,来自文档:

params 是参数列表或字典。无论您的数据库引擎如何,您都将在查询字符串中使用 %s 占位符作为列表,或使用 %(key)s 占位符作为字典(当然,其中的键被字典键替换)。此类占位符将替换为 params 参数中的参数。

  dests1 = destination.objects.raw(
   "select *from travello_destination where name = %s or name=%s", params=['Bangalore','Mumbai'])

我也建议你使用ORM而不是原始查询

于 2020-04-18T19:16:05.740 回答