2👍
✅
You’re trying to insert the string "id"
, rather than the value of the variable id
.
It should be:
cursor.execute(sql, (id,))
Of course, there’s no reason to be using raw SQL for this at all.
0👍
As Daniel said, “there’s no reason to be using raw SQL.” Instead, you should make use of Django’s model syntax for inserting new items into the datebase, like so:
e = Evento.objects.create(id_unidad=id)
This one line can replace everything below print type(id)
. More importantly, using Django’s Models for database manipulation gives you SQL injection protection for free.
- [Answered ]-Django-redis configuration to use socket rather than TCP
- [Answered ]-How do django send ajax response?
- [Answered ]-Python Celery init.d script OSError: [Errno 1] Operation not permitted
- [Answered ]-Django CreateView with form_class not creating model
- [Answered ]-Purpose of ugettext inside of Models
Source:stackexchange.com