0

Does this work? and stored it in a database, now I want to display the same data on my own website, but it doesn't work. Help please!

@auth.route('/')
def home():
    def GetBookLink():
        mydb = mysql.connector.connect(
                    host='localhost',
                    user = 'Salahudheen',
                    passwd = 'Salahudheen1!',
                    database = 'testdatabase'
                    )
        mycursor = mydb.mycursor()

        
        
        mycursor.execute("SELECT * FROM ScrapedBooks") 
        DBData = mycursor.fetchall() 
        mycursor.close()
         

    return render_template("home.html", ScrapedBookData = DBData)

HTML :

{% extends "base.html"%} {% block title %}Home{% endblock %}{% block content %}    
<h1>{{ScrapedBookData}}</h1>
{% endblock %}

Of course this isn't the format I'm going to display it in, but I just want to learn how to display it first

1 Answer 1

1

You defined GetBookLink function inside home function and never calls former. GetBookLink function is also missing return statement. Please try follwing code which is minimal change repair:

@auth.route('/')
def home():
    def GetBookLink():
        mydb = mysql.connector.connect(
                    host='localhost',
                    user = 'Salahudheen',
                    passwd = 'Salahudheen1!',
                    database = 'testdatabase'
                    )
        mycursor = mydb.mycursor()

        
        
        mycursor.execute("SELECT * FROM ScrapedBooks") 
        DBData = mycursor.fetchall() 
        mycursor.close()
        return DBData
         
    DBData = GetBookLink()
    return render_template("home.html", ScrapedBookData = DBData)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.