Dec-30-2019, 03:56 PM
Hi..I want to save the data from MySQL to CSV in Flask. The data that need to be saved, consists of id,q1 and q2. The problem is, it does not generate all the data. Instead, it just shown id,q1 and q2 only in the csv, as shown example below:
-------------------
id q1 q2
------------------
id q1 q2
-------------------
The code are below:
-------------------
id q1 q2
------------------
id q1 q2
-------------------
The code are below:
@app.route('/article/<string:id>/') def article(id): # Create cursor cur = mysql.connection.cursor() # Get article result = cur.execute("SELECT id,q1,q2 FROM table WHERE id = %s", [id]) article = cur.fetchall() with open('database.csv', 'w', newline= '') as f: a = csv.writer(f, delimiter=',') a.writerows(article) ## closing paren added if result > 0: return render_template('article.html', article=article) else: msg = 'No Articles Found' return render_template('article.html', msg=msg)Hope you can help me