执行原生SQL:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 from django.db import connection, connections 2 cursor = connection.cursor() 3 cursor.execute( 4 """select * from tb where nid=%s""",[user.nid, ]) 5 result = cursor.fetchall()
赋值放在第二个参数,防止SQL注入
对于时间进行格式化:
- SQLite时间戳---->日期格式:
1 strftime("%Y-%m-01",ctime)
转换回时间戳:
strftime('%s',strftime("%Y-%m-01",ctime))
2.MySQ时间戳---->日期格式:
1 date_format(NOW(),'%Y-%m-%d %H:%i:%s')
MYSQL日期--->时间戳:
UNIX_TIMESTAMP('2006-11-04 12:23:00');
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
JS时间戳+new Date()
JS日期格式new Date()