擅长:python、mysql、java
<p>您还可以在查询中使用字典和变量:</p>
<pre><code>my_dict = {
'id': 10,
'city': 20,
'state': 30
}
mymodel.objects.raw('''SELECT * from users
where id = %(id)s and
city = %(city)s and
state = %(state)s ''', my_dict)
</code></pre>
<p>你可以在这里阅读更多内容:<a href="https://docs.djangoproject.com/en/1.10/topics/db/sql/#passing-parameters-into-raw" rel="noreferrer">https://docs.djangoproject.com/en/1.10/topics/db/sql/#passing-parameters-into-raw</a></p>