Flask Vue的乙個示例

2022-05-26 21:03:12 字數 2983 閱讀 5704

這裡記錄下乙個flask+vue的乙個示例

1.系統環境:python3.7

sqlite3資料庫,資料庫名稱:books.db

2.專案結構

",title='測試'

)"/api/books")

defbooks():

conn = sqlite3.connect("

books.db")

conn.row_factory =sqlite3.row

cur =conn.cursor()

sql = "

select * from books

"rows =cur.execute(sql).fetchall()

rows = [dict(row) for row in

rows]

return jsonify(rows)

4.index.html

doctype html

>

<

html

lang

="en"

>

<

head

>

<

meta

charset

="utf-8"

>

<

meta

name

="viewport"

content

="width=device-width,initial-scale=1.0"

>

<

title

>flask vue

title

>

<

script

src=""

>

script

>

<

script

src=""

>

script

>

head

>

<

body

>

<

div

id>

<

h1>flask & vue.js }

h1>

<

table

border

="1"

cellpadding

=5 cellspacing

=5>

<

tr>

<

td>id

td>

<

td>標題

td>

<

td>作者

td>

<

td>定價

td>

tr>

<

tr v-for

="book in books"

>

<

td>[[book.id]]

td>

<

td>[[book.title]]

td>

<

td>[[book.author]]

td>

<

td>[[book.price]]

td>

tr>

table

>

<

script

>

var=

newvue(,

delimiters:["[[

","]]

"],mounted:

function

(), methods:,err

=>

); }}})

script

>

div>

body

>

html

>

5.構造資料庫語句

1

.建立資料庫

sqlite3 books.db

2.建立表

create

table books(id int

primary

keynot

null,title text

notnull,author text

notnull,price real

notnull);3

.插入記錄

insert

into books values(1,'

python

','eason

',39.0

);insert

into books values(2,'

django

','eason

',99.0

);insert

into books values(3,'

flask

','eason

',129.0

);insert

into books values(4,'

vuejs

','eason

',50.0);

6.示例效果

xml的乙個示例

function.h cstring openfile cstring cstring getcontext cstring,int,int void str2array cstring struct xmlnode function.cpp include include include incl...

NHibernate的乙個示例

一 建立poco實體 工廠表factoryentity,關聯企業表companyentiry,company id關聯t pm company表 企業表 manytoone name companyentity classtype typeof companyentity lazy laziness...

乙個PlaySound示例

using system using system.collections using system.componentmodel using system.runtime.interopservices internal class helpers dllimport winmm public s...