1π
β
I found the solution. In case you are using Django, please refer to Burhan Khalid easy solution that solves everything:
from yourapp.models import url_list
new_url = url_list(url_id=url_i, url_name=url_n, url_title=url_t)
new_url.save()
BUT, if you are not working in models or Django (or Both) and involves a normal table, let me draw your attention to the fact that the url_t variable is neither a string nor a unicode variable. When I did this:
type(url_t)
I got the type of url_t and it returned:
<class 'bs4.something'>
Which is something we donβt want.
We want:
<type 'unicode'>
To convert it to unicode, just do the following:
unicode(url_t)
Even after converting it to unicode, I noticed the problem persisted. Then, with a few more experiments, I did the following:
url_t=str(url_t)
url_t=url_t[1:]
Voila. Problem solved.
π€user3504239
1π
Instead of messing with cursors and raw SQL, use the database api:
from yourapp.models import url_list
new_url = url_list(url_id=url_i, url_name=url_n, url_title=url_t)
new_url.save()
π€Burhan Khalid
- [Answered ]-Django β set expiry for a certain key in session
- [Answered ]-Django select_related works in template rendering?
Source:stackexchange.com