error Ascii ครับ

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: error Ascii ครับ

Re: error Ascii ครับ

โดย mindphp » 25/05/2019 3:36 am

ไฟล์ template .html
ไม่ต้องใส่

โค้ด: เลือกทั้งหมด

# -*- coding: utf-8 -*-

Re: error Ascii ครับ

โดย thatsawan » 24/05/2019 4:24 pm

ลองเช็คปัญหาเป็นที่ python หรือ Template ไปที่ละจุดๆ ก่อน

Re: error Ascii ครับ

โดย thatsawan » 24/05/2019 3:58 pm

โค้ด: เลือกทั้งหมด

                name = name.encode('ascii')

โค้ด: เลือกทั้งหมด

                name = name.encode('utf-8')  

Re: error Ascii ครับ

โดย thatsawan » 24/05/2019 3:55 pm

Re: error Ascii ครับ

โดย teenproza7 » 24/05/2019 3:26 pm

tatiya เขียน:ใส่อันนี้บนหัวยังครับ

โค้ด: เลือกทั้งหมด

# -*- coding: utf-8 -*-

ใส่แล้วครับทั้ง py และ html
Selection_786.png
Selection_786.png (6.89 KiB) Viewed 1630 times
Selection_785.png
Selection_785.png (6.93 KiB) Viewed 1630 times

Re: error Ascii ครับ

โดย tatiya » 24/05/2019 3:22 pm

ใส่อันนี้บนหัวยังครับ

โค้ด: เลือกทั้งหมด

# -*- coding: utf-8 -*-

error Ascii ครับ

โดย teenproza7 » 24/05/2019 3:19 pm

ผมเรียกข้อมูลจากฐานข้อมูลมาแสดงแล้ว เกิด Error แบบนี้ครับ

รูปภาพ

code

โค้ด: เลือกทั้งหมด

@app.route('/show')
def show():

        cur.execute('SELECT version()')
        sql = "SELECT * FROM genpdf ORDER BY fileid DESC LIMIT 3"
        sql = sql.encode('utf-8')
        cur.execute(sql)
        rows = cur.fetchall()
        return render_template("show.html", rows=rows)
หน้า html

โค้ด: เลือกทั้งหมด

#-*- coding=utf-8 -*-

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>แสดงข้อมูล</title>

</head>

   <fo>
      <table border="1" 1cellspacing="5" width="80%" height="5" align="center">
            <a href = "/">กลับหน้าหลัก</a>
         <thead>
            <td align="center">ID</td>
            <td align="center">ชื่อไฟล์</td>
            <td align="center">คำอธิบาย</td>

            <td colspan="2" align="center" width="10%">เครื่องมือ</td>

         </thead>
             {% for row in rows %}
            <tr>

               <td>{{ row[0] }}</td>
               <td>{{ row[1] }}</td>
               <td>{{ row[2] }}</td>

               <td>  <form action="/iddel/{{ row[0] }}" method="post"> <input type="submit" value="ลบข้อมูล" /> </form></td>
                <td><form action="/enteredit/{{ row[0] }}" method="post"> <input type="submit" value="แก้ไข" /> </form></td>

            </tr>
         {% endfor %}
      </table>



   </body>
</html>

ข้างบน