Home:ALL Converter>How to use external database in django?

How to use external database in django?

Ask Time:2019-05-27T17:12:44         Author:Ishaan007

Json Formatter

I am new to django, I have pretty good idea of basics. I am able to build model(Django database) and use it in templates. But now I want to connect external database to the django templates. How do I do that? I referred to the following link - Pulling data to the template from an external database with django But I am still running into errors.

My views.py file looks like this :


    def view(request):
        conn = sqlite3.connect("data_new.db")
        try:
            cur = conn.cursor()
            cur.execute("delete from data_new where date = ''; ")
            cur.execute("select * from data_new;")
            results = cur.fetchall()
        finally:
            conn.close()
        return render("main.html",{"results": results})

Following error is displayed when I run it on server : -

TypeError at /

join() argument must be str or bytes, not 'dict'

Author:Ishaan007,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/56323004/how-to-use-external-database-in-django
yy