- django中使用原生sql
from django.db import connection
cursor = connection.cursor()
cursor.execute("select * from xx where id=1")
row = cursor.fetchone()
users = User.objects.raw("select * from user where name='xx'")
for user in users:
print(user.name)
查询结果对应model
- sql 使用正则
select * from user where name regexp 'a|b';