比尔云BierYun--阿里云最新优惠活动
阿里云优惠码丨阿里云代金券

docker配置mysql主从与django实现读写分离

docker配置mysql主从与django实现读写分离

一、搭建主从mysql环境#

1 下载mysql镜像#

Copy
docker pull mysql:5.7

2 运行刚下载的mysql镜像文件#

Copy
# 运行该命令之前可以使用`docker images`是否下载成功

docker run -p 3307:3306 --name mysql-master -v /mysql/conf:/etc/mysql/conf.d -v /mysql/logs:/logs -v /mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123 -itd  mysql:5.7

上面的意思是将mysql在后台启动运行, 并且这个mysql是运行在宿主机3307端口上的,等会django连接的也是这个端口, –name 是将这个mysql应用取了个别名。3个-v是指定容器中的mysql的相关文件路径与宿主机路径的映射关系,这样便能通过修改宿主机的配置文件而达到修改容器中的mysql的配置了。-e 指定的是进入容器后的mysql的初始密码为123。

3 修改主服务器的配置文件#

vim /mysql/conf/mysql.cnf

Copy
[mysqld]
pid-file    = /var/run/mysqld/mysqld.pid
socket    = /var/run/mysqld/mysqld.sock
datadir    = /var/lib/mysql

symbolic-links=0

character-set-server = utf8   
#skip-networking  
innodb_print_all_deadlocks = 1
max_connections = 2000  
max_connect_errors = 6000  
open_files_limit = 65535  
table_open_cache = 128   
max_allowed_packet = 4M  
binlog_cache_size = 1M  
max_heap_table_size = 8M  
tmp_table_size = 16M  
  
read_buffer_size = 2M  
read_rnd_buffer_size = 8M  
sort_buffer_size = 8M  
join_buffer_size = 28M  
key_buffer_size = 4M  
  
thread_cache_size = 8  
  
query_cache_type = 1  
query_cache_size = 8M  
query_cache_limit = 2M  
  
ft_min_word_len = 4  
  
log-bin = mysql-bin
server-id = 1
binlog_format = mixed  
 
performance_schema = 0  
explicit_defaults_for_timestamp  
  
#lower_case_table_names = 1  
  
interactive_timeout = 28800  
wait_timeout = 28800  

#Recommended in standard MySQL setup  
  
sql_mode=NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER,STRICT_TRANS_TABLES   
  
[mysqldump]  
quick  
max_allowed_packet = 16M  
  
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M

4 重启mysql的服务#

Copy
docker restart mysql-master

5 进入主服务器中的mysql终端#

Copy
docker exec -it mysql-master /bin/bash

# 用户名登陆用户名密码
mysql -uroot -p123
# 执行show master status; 查看主服务器的连接信息
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 |      154 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

# 这也说明了上面的配置成功了, 上面显示的两个参数(log_file和log_position)等会从服务器需要配置使用

# 接下来要创建从服务器使用的账户, 授予权限
mysql> GRANT REPLICATION SLAVE ON *.* to 'reader'@'%' identified by '123';
Query OK, 0 rows affected, 1 warning (0.00 sec)

# 更新权限
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

6 创建并运行从服务器#

Copy
docker run -p 3308:3306 --name mysql-slave -v /mysql-slave/conf:/etc/mysql/conf.d -v /mysql-slave/logs:/logs -v /mysql-slave/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123 -itd mysql:5.7

7 编辑从服务其的配置文件#

vim /mysql-slave/conf/mysql.cnf

Copy
[mysqld]
pid-file    = /var/run/mysqld/mysqld.pid
socket    = /var/run/mysqld/mysqld.sock
datadir    = /var/lib/mysql

symbolic-links=0

character-set-server = utf8   
#skip-networking  
innodb_print_all_deadlocks = 1
max_connections = 2000  
max_connect_errors = 6000  
open_files_limit = 65535  
table_open_cache = 128   
max_allowed_packet = 4M  
binlog_cache_size = 1M  
max_heap_table_size = 8M  
tmp_table_size = 16M  
  
read_buffer_size = 2M  
read_rnd_buffer_size = 8M  
sort_buffer_size = 8M  
join_buffer_size = 28M  
key_buffer_size = 4M  
  
thread_cache_size = 8  
  
query_cache_type = 1  
query_cache_size = 8M  
query_cache_limit = 2M  
  
ft_min_word_len = 4  
  
log-bin = mysql-bin
server-id = 2
binlog_format = mixed  
 
performance_schema = 0  
explicit_defaults_for_timestamp  
  
#lower_case_table_names = 1  
  
interactive_timeout = 28800  
wait_timeout = 28800  

#Recommended in standard MySQL setup  
  
sql_mode=NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER,STRICT_TRANS_TABLES   
  
[mysqldump]  
quick  
max_allowed_packet = 16M  
  
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M

8 配置从服务器#

Copy
docker exec -it mysql-slave /bin/bash
# 进入mysql
mysql -uroot -p123

# 配置自己的主服务器信息
change master to master_host='172.17.0.2',master_user='reader',master_password='123',master_log_file='mysql-bin.000001',master_log_pos=154;

查看主服务器的ip地址信息, 容器之间的通信需要使用内网地址。

Copy
[root@localhost /]# docker inspect --format='{{.NetworkSettings.IPAddress}}' mysql-master
172.17.0.2

9 从服务器启动I/O 线程和SQL线程#

不带任何参数,表示同时启动I/O 线程和SQL线程。
I/O线程从主库读取bin log,并存储到relay log中继日志文件中。
SQL线程读取中继日志,解析后,在从库重放。

Copy
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)

# Slave_IO_Running: Yes,Slave_SQL_Running: Yes即表示启动成功。
mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.17.0.2
                  Master_User: reader
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 591
               Relay_Log_File: 2ae1346b43b9-relay-bin.000002
                Relay_Log_Pos: 757
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB:

10 测试#

在主服务器上创建slave_test数据库

create database slave_test charset utf8;

在从服务器上查看slave_test数据库的数据

Copy
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| slave_test         |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

上面的结果说明了数据库的主从创建已经成功。

二、django实现读写分离#

1 创建数据库操作的路由分发类#

路径: utils.db_router.py

Copy
class MasterSlaveDBRouter(object):
    """数据库主从读写分离路由"""

    def db_for_read(self, model, **hints):
        """读数据库"""
        return "slave"

    def db_for_write(self, model, **hints):
        """写数据库"""
        return "default"

    def allow_relation(self, obj1, obj2, **hints):
        """是否运行关联操作"""
        return True

    def allow_migrate(self, db, app_label, model_name=None, **hints):
        """允许迁移"""
        return True

2 settings文件配置#

数据库的配置
Copy
# 数据库的配置
DATABASES = {
    # 主库
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'HOST': '192.168.12.78',  # docker宿主机的ip地址
        'PORT': 3307,  # 主
        'USER': 'root',  # 主数据库用户名
        'PASSWORD': '123',  # 主数据库密码
        'NAME': 'slave_test'  # 主数据库名字
    },
    # 从库, 负责写
    'slave': {
        'ENGINE': 'django.db.backends.mysql',
        'HOST': '192.168.12.78',  # docker宿主机的ip地址
        'PORT': 3308,  # 从
        'USER': 'root',  # 从数据库用户名
        'PASSWORD': '123',  # 从数据库密码
        'NAME': 'slave_test'  # 从数据库名字
    }
}
指定数据库的路由分发类
Copy
DATABASE_ROUTERS = ['api.utils.db_router.MasterSlaveDBRouter']

3 models文件#

Copy
from django.db import models

class Book(models.Model):
    nid = models.AutoField(primary_key=True)
    name = models.CharField(max_length=200)
    publish = models.CharField(max_length=32)
    price = models.DecimalField(max_digits=6, decimal_places=2)

4 迁移文件#

Copy
python3 manage.py makemigrations
python manage.py migrate

5 数据的简单获取与快速添加#

简单写了个爬虫获取了一些书籍的数据

book_info.json

Copy
{"name": "丰子恺万般滋味,都是生活", "publish": "华中科技大学出版社", "price": 21.0}
{"name": "皮囊(350万册纪念版。直面人生的终极问题,刻在骨头里的故事,容纳一个个既失去家乡又未到达远方的生命。感动千万读者的国", "publish": "天津人民出版社", "price": 23.65}
{"name": "自在独行 贾平凹的独行世界(畅销300万册的国民精神读本,中国作家协会推荐精读)", "publish": "长江文艺出版社", "price": 18.6}
{"name": "一只特立独行的猪", "publish": "北京十月文艺出版社", "price": 17.5}
{"name": "三毛全集02:撒哈拉的故事(1-9年级必读书单)", "publish": "北京十月文艺出版社", "price": 24.2}
{"name": "沉默的大多数(手稿珍藏版)", "publish": "北京十月文艺出版社", "price": 17.5}
{"name": "我与地坛(纪念版)(1-9年级必读书单)", "publish": "人民文学出版社", "price": 17.4}
{"name": "笑场(《吐槽大会》总策划、《奇葩说》导师李诞首部作品,精装版)", "publish": "湖南文艺出版社", "price": 17.1}
{"name": "看见", "publish": "广西师范大学出版社", "price": 28.6}
{"name": "汪曾祺散文精选集:万事有心,人间有味(麦家、冯唐、贾平凹等极力推崇)", "publish": "中国友谊出版公司", "price": 21.0}
{"name": "爱你就像爱生命(精装彩插典藏版)", "publish": "湖南文艺出版社", "price": 18.9}
{"name": "文化苦旅 新版", "publish": "长江文艺出版社", "price": 28.7}
{"name": "白岩松:白说", "publish": "长江文艺出版社", "price": 23.8}
{"name": "余秋雨 文化苦旅(1-9年级必读书单)", "publish": "长江文艺出版社", "price": 27.4}
{"name": "目送:龙应台“人生三书”之三(彩插新版)", "publish": "广西师范大学出版社", "price": 32.2}
{"name": "欢喜:冯唐2020金句日历(冯唐新书)", "publish": "中国华侨出版社", "price": 52.8}
{"name": "春风十里不如你:一本书读尽冯唐人生金线,年轻时极尽欢喜,年长后极尽通透。(当当专享冯唐可装裱书法(飘银纸))", "publish": "北京联合出版有限公司", "price": 52.0}
{"name": "人间草木 汪曾祺典藏文集", "publish": "北京时代华文书局", "price": 16.3}
{"name": "愿你有英雄呵护,也有勇气独立(赵露思抖音同款书,袁姗姗、宋伊人等暖心推荐,当红明星都在看的爆款佳作)", "publish": "浙江文艺出版社", "price": 22.5}
{"name": "戴建业 你听懂了没有(国民教授戴建业随笔精选集。陈引驰、骆玉明、六神磊磊推荐!火辣辣的文字写人生百态,有才有识,有情有", "publish": "上海文艺出版社", "price": 33.3}
{"name": "孤独是生命的礼物", "publish": "长江文艺出版社", "price": 17.1}
{"name": "天长地久:给美君的信(龙应台暌违十年重磅新作)", "publish": "湖南文艺出版社", "price": 29.0}
{"name": "李银河说爱情", "publish": "北京十月文艺出版社", "price": 22.5}
{"name": "愿你,归来仍是少年(林清玄启悟人生系列)", "publish": "长江文艺出版社", "price": 21.3}
{"name": "人生最美是清欢(林清玄经典散文集,执笔45周年白金纪念版!)", "publish": "北京十月文艺出版社", "price": 39.1}
{"name": "妞妞:一个父亲的札记", "publish": "北京十月文艺出版社", "price": 21.0}
{"name": "三毛全集05:梦里花落知多少", "publish": "北京十月文艺出版社", "price": 17.5}
{"name": "愿你历尽千帆,归来仍是少年", "publish": "光明日报出版社", "price": 15.7}
{"name": "三毛全集01:雨季不再来", "publish": "北京十月文艺出版社", "price": 17.5}
{"name": "阿勒泰的角落(李娟成名作四色典藏版,随书附赠四季手绘书签)", "publish": "新星出版社", "price": 18.0}
{"name": "龙应台“人生三书”全3册套装", "publish": "广西师范大学出版社", "price": 81.6}
{"name": "林清玄散文精选(套装两册)", "publish": "作家出版社", "price": 28.0}
{"name": "风会记得一朵花的香(修订版)", "publish": "金城出版社", "price": 14.9}
{"name": "孤独六讲", "publish": "长江文艺出版社", "price": 34.6}
{"name": "我与地坛(精装)插图版", "publish": "湖南文艺出版社", "price": 20.0}
{"name": "送你一颗子弹", "publish": "东方出版中心", "price": 23.6}
{"name": "亲爱的安德烈(插图第2版)", "publish": "广西师范大学出版社", "price": 19.8}
{"name": "我与地坛", "publish": "人民文学出版社", "price": 21.4}
{"name": "朗读者(1-3辑)(荣获2017年度大众喜爱的50种图书)", "publish": "人民文学出版社", "price": 104.5}
{"name": "雅舍小品 (收录 谈话的艺术 骂人的艺术 时间即友谊等)", "publish": "天津人民出版社", "price": 13.2}
{"name": "慢煮生活(汪曾祺经典散文集,执笔75周年白金纪念版!畅销领衔之作,升级回馈)", "publish": "江苏凤凰文艺出版社", "price": 12.0}
{"name": "人生不过如此(林语堂著)", "publish": "陕西师范大学出版社", "price": 9.7}
{"name": "把生活过成你想要的样子", "publish": "北京联合出版公司", "price": 30.2}
{"name": "遥远的向日葵地(2017中国好书)(第七届鲁迅文学奖获奖作品)", "publish": "花城出版社", "price": 20.9}
{"name": "给青年的十二封信", "publish": "江苏凤凰文艺出版社", "price": 12.0}
{"name": "走到人生边上——自问自答(增订本)(普通本)", "publish": "商务印书馆", "price": 20.3}
{"name": "明天也是小春日和(某瓣9.5分热映影片《人生果实》《积存时间的生活》原著)", "publish": "新星出版社", "price": 19.7}
{"name": "美的沉思(蒋勋畅销20年经典之作)", "publish": "湖南美术出版社", "price": 27.6}
{"name": "愿所有相遇,都恰逢其时", "publish": "浙江文艺出版社", "price": 19.9}
{"name": "【新华正版包邮】中国文化课 余秋雨 著 樊登推荐", "publish": "中国青年出版社", "price": 88.3}
{"name": "此刻的温柔", "publish": "浙江文艺出版社", "price": 24.9}
{"name": "爱你就像爱生命(五线谱情书珍藏版)", "publish": "北京十月文艺出版社", "price": 17.5}
{"name": "长长的路 我们慢慢走", "publish": "光明日报出版社", "price": 34.4}
{"name": "早晨从中午开始(故事里的中国,董卿诚意推荐)", "publish": "北京十月文艺出版社", "price": 11.0}
{"name": "愿有人陪你颠沛流离", "publish": "湖南文艺出版社", "price": 17.0}
{"name": "谢谢你离开我(全新精装增订本。央视《朗读者》张小娴,深情朗读《爱情的餐桌》)", "publish": "湖南文艺出版社", "price": 18.9}
{"name": "慢煮生活(汪曾祺逝世20周年 精装纪念散文集)", "publish": "江苏凤凰文艺出版社", "price": 23.7}
{"name": "无所畏(2018年冯唐全新作品,一部坦露自我的真诚之作)", "publish": "北京联合出版有限公司", "price": 29.8}
{"name": "病隙碎笔(纪念版)", "publish": "湖南文艺出版社", "price": 16.7}
{"name": "这么慢,那么美", "publish": "中国友谊出版公司", "price": 25.9}
{"name": "食事(精装典藏版!汪曾祺作品精选,关于美食与爱的散文作品!一支淡笔抒写出存留心底的人间至味!)", "publish": "江苏人民出版社", "price": 16.4}
{"name": "冬牧场(精装典藏版)", "publish": "新星出版社", "price": 29.5}
{"name": "千年一叹", "publish": "长江文艺出版社", "price": 25.2}
{"name": "独处的力量(精选收录余光中、周国平、贾平凹等几十位知名作家的经典散文,愿每个人都能享受人群的繁华,又能妥善安置独处的时", "publish": "天津人民出版社", "price": 27.4}
{"name": "林清玄散文精选", "publish": "长江文艺出版社", "price": 18.2}
{"name": "【限时秒杀包邮】鲁迅正版全集8册朝花夕拾狂人日记 阿Q正传 孔乙己 彷徨 中小学生阅读四五六年级课外书儿童书籍故事书6", "publish": "红旗出版社", "price": 29.5}
{"name": "三毛全集03:稻草人手记", "publish": "北京十月文艺出版社", "price": 16.0}
{"name": "一个人的村庄(新疆乡土作家刘亮程的经典之作!)", "publish": "春风文艺出版社", "price": 16.8}
{"name": "我所理解的生活(三十岁的男人开始系统地思考关于生活的一切,韩寒难得如此诚恳)", "publish": "浙江文艺出版社", "price": 17.65}
{"name": "我的阿勒泰(新版)", "publish": "长江文艺出版社", "price": 23.9}
{"name": "灵魂有香气的女子(畅销200万册!超级偶像周洁琼香气推荐。新增20%从未发表美人故事。愿我们读懂别人的故事,过好自己的", "publish": "上海文艺出版社", "price": 33.8}
{"name": "朗读者Ⅱ(套装1-3)", "publish": "人民文学出版社", "price": 112.5}
{"name": "听什么歌都像在唱自己", "publish": "人民日报出版社", "price": 24.0}
{"name": "琦君散文精选", "publish": "长江文艺出版社", "price": 18.8}
{"name": "汪曾祺典藏文集人间有味", "publish": "北京时代华文书局", "price": 18.3}
{"name": "在时光里流浪(江一燕2019全新力作)", "publish": "湖南文艺出版社", "price": 24.7}
{"name": "一生自在:季羡林的自在智慧(《榜样阅读》蔡徐坤品读推荐)", "publish": "江苏凤凰文艺出版社", "price": 21.4}
{"name": "海风中失落的血色馈赠(2018新版)", "publish": "上海文艺出版社", "price": 18.8}
{"name": "生活,是很好玩的(汪曾祺散文精选集,20周年精装纪念版。“在平淡的生活中,发现世间的美好”。沈从文、贾平凹、冯唐极力推", "publish": "江西人民出版社", "price": 26.0}
{"name": "行者无疆", "publish": "长江文艺出版社", "price": 23.0}
{"name": "毕淑敏精选集", "publish": "北京燕山出版社", "price": 14.0}
{"name": "我爱这热闹的生活", "publish": "江西人民出版社", "price": 31.0}
{"name": "千年一叹", "publish": "作家出版社", "price": 18.0}
{"name": "你也走了很远的路吧(卢思浩2017作品)", "publish": "湖南文艺出版社", "price": 18.9}
{"name": "缘缘堂随笔", "publish": "天津人民出版社", "price": 8.5}
{"name": "三毛全集06:万水千山走遍", "publish": "北京十月文艺出版社", "price": 17.5}
{"name": "玩儿(于谦作品,郭德纲作序推荐。2018精装增订!)", "publish": "湖南文艺出版社", "price": 23.7}
{"name": "山河之书", "publish": "长江文艺出版社", "price": 27.4}
{"name": "一生所寻不过爱与自由", "publish": "北京联合出版有限公司", "price": 19.4}
{"name": "张晓风散文精选——名家散文经典", "publish": "长江文艺出版社", "price": 18.2}
{"name": "简媜精选集:你笑起来真像好天气(教育部、人民日报、十点读书强烈推荐)", "publish": "北京联合出版有限公司", "price": 23.7}
{"name": "活着活着就老了(冯唐经典杂文集 长销十年/全新序言 精装升级/高晓松、李银河、柴静、李敬泽推荐)", "publish": "浙江文艺出版社", "price": 24.0}
{"name": "不畏将来 不念过去", "publish": "江苏文艺出版社", "price": 15.2}
{"name": "雨夜短文(余秋雨2019全新散文力作!大手笔写小短文,人世间,多少人唯有在雨夜,在万籁俱寂中才能醒悟和微笑?越无声,越", "publish": "天地出版社", "price": 27.6}
{"name": "敢于孤独的勇气(2019年周国平全新散文精选集)", "publish": "浙江人民出版社", "price": 27.6}
{"name": "精神明亮的人", "publish": "书海出版社", "price": 23.8}
{"name": "白岩松作品集:白说+万事尽头,终将如意+痛并快乐着?新版+幸福了吗?新版(套装共4册)", "publish": "HarperCollins UK", "price": 96.8}
{"name": "幸得诸君慰平生", "publish": "清华大学出版社", "price": 31.3}
{"name": "人间草木(1-9年级必读书单)", "publish": "天津人民出版社", "price": 13.5}
{"name": "一剪宋朝的时光(品味宋词的清丽婉转与风流多情,静静感受中华文化之美)", "publish": "湖南文艺出版社", "price": 17.2}
{"name": "《读者》六年典藏精选·美文彩插系列2(共四册)", "publish": "时代文艺出版社", "price": 76.0}
{"name": "时间在左,尘缘在右", "publish": "青岛出版社", "price": 18.9}
{"name": "先谋生,再谋爱(“灵魂有香气的女子”系列)", "publish": "天津人民出版社", "price": 17.15}
{"name": "恰到好处的幸福(新版)", "publish": "湖南文艺出版社", "price": 18.9}
{"name": "三千年前那朵静夜的莲开(白落梅2019年新作,细品《诗经》之美)", "publish": "湖南文艺出版社", "price": 19.5}
{"name": "我喜欢人生快活的样子(汪涵,大张伟 力荐的人生态度!)", "publish": "湖南文艺出版社", "price": 22.8}
{"name": "非洲三万里:毕淑敏全新创作的旅行主题书", "publish": "湖南文艺出版社", "price": 22.8}
{"name": "等一朵花开", "publish": "北京联合出版公司", "price": 29.0}
{"name": "白岩松:万事尽头,终将如意", "publish": "长江文艺出版社", "price": 25.2}
{"name": "写作这回事:创作生涯回忆录(2018新版)", "publish": "上海文艺出版社", "price": 25.3}
{"name": "抵错(限量签名版,随机发放)", "publish": "江苏凤凰文艺出版社", "price": 27.0}
{"name": "积存时间的生活(某瓣9.5分热映影片《人生果实》《积存时间的生活》原著)", "publish": "中国青年出版社", "price": 22.8}
{"name": "文学课(浓缩沈从文60余年文学经验的阅读写作课)", "publish": "四川人民出版社", "price": 22.5}
{"name": "致女儿书", "publish": "北京十月文艺出版社", "price": 17.5}
{"name": "我们都是宇宙中的微尘", "publish": "北京十月文艺出版社", "price": 19.5}
{"name": "愿人生从容", "publish": "九州出版社", "price": 20.6}
{"name": "离开前请叫醒我:卢思浩新品", "publish": "湖南文艺出版社", "price": 17.5}
{"name": "见字如面(《见字如面》节目组唯一官方授权)", "publish": "湖南文艺出版社", "price": 23.7}
{"name": "游荡集(十三邀中,许知远写下的游荡文字)", "publish": "湖南文艺出版社", "price": 21.4}
{"name": "请回答1998(马云、马化腾、刘强东、章子怡、赵薇……还有我们的人生,早已在20年前埋下了伏笔)", "publish": "江苏凤凰文艺出版社", "price": 27.4}
{"name": "素履之往(精装)", "publish": "广西师范大学出版社", "price": 19.5}
{"name": "简媜:水问(精装典藏纪念版)", "publish": "台海出版社", "price": 25.2}
{"name": "沉默的大多数", "publish": "群言出版社", "price": 18.0}
{"name": "浴血荣光(全新再版,团购电话:400-1066666转6)", "publish": "北京联合出版公司", "price": 22.5}
{"name": "日食记:用自己喜欢的方式吃一生", "publish": "四川文艺出版社", "price": 26.9}
{"name": "月童度河(安妮宝贝改名后全新散文小说集,电子书6月28日开始销售)", "publish": "北京十月文艺出版社", "price": 16.9}
{"name": "听听那冷雨(当代文学大师余光中经典作品,全新未删节插图典藏版,畅销两岸50年的传世之作!)", "publish": "中国友谊出版公司", "price": 27.0}
{"name": "此时众生:蒋勋的至美生活周记", "publish": "湖南文艺出版社", "price": 22.8}
{"name": "此生未完成(增订新版)", "publish": "湖南文艺出版社", "price": 20.0}
{"name": "把日子过得有趣", "publish": "江西美术出版社", "price": 18.4}
{"name": "烟愁", "publish": "化学工业出版社", "price": 15.2}
{"name": "灵魂只能独行", "publish": "北京十月文艺出版社", "price": 22.5}
{"name": "旧日的静定", "publish": "山东画报出版社", "price": 34.0}
{"name": "一卷大唐的风华 (白落梅2018年全新作品,解读唐诗的唯美佳作)", "publish": "湖南文艺出版社", "price": 19.0}
{"name": "做一个刚刚好的女子:不攀附,不将就", "publish": "青岛出版社", "price": 16.7}
{"name": "精神明亮的人", "publish": "书海出版社", "price": 27.0}
{"name": "余秋雨散文精选(名家散文典藏·彩插版)", "publish": "长江文艺出版社", "price": 25.8}
{"name": "丰子恺活着本来单纯", "publish": "江苏文艺出版社", "price": 21.4}
{"name": "林清玄给青少年的生命课(全两册)", "publish": "浙江文艺出版社", "price": 45.0}
{"name": "古典之殇:纪念原配的世界", "publish": "书海出版社", "price": 17.5}
{"name": "三毛全集07:送你一匹马", "publish": "北京十月文艺出版社", "price": 16.0}
{"name": "我决定活得有趣", "publish": "北京时代华文书局", "price": 19.7}
{"name": "东京一年", "publish": "中信出版社", "price": 42.8}
{"name": "借我一生", "publish": "作家出版社", "price": 21.0}
{"name": "世界很大,幸好有你", "publish": "江苏文艺出版社", "price": 18.6}
{"name": "林清玄:岁月静好 不忘初心(精装典藏版)", "publish": "北京联合出版公司", "price": 19.2}
{"name": "你要去相信,没有到不了的明天(卢思浩2018全新增订)", "publish": "湖南文艺出版社", "price": 21.0}
{"name": "雅舍小品(2019版,完整收录初版《雅舍小品》)【果麦经典】", "publish": "上海文艺出版社", "price": 19.9}
{"name": "我在等风,也在等你(民国大师们的缱绻情书:看他们的爱情,悟自己的人生。 中国出版集团年度重磅作品。)", "publish": "现代出版社", "price": 14.0}
{"name": "老舍散文(汪曾祺、王朔极力推崇的语言大师,优美典藏版,精选老舍64篇经典散文)", "publish": "天津人民出版社", "price": 21.0}
{"name": "残雪文学回忆录(2019年诺贝尔文学奖提名者作品)", "publish": "广东人民出版社", "price": 27.6}
{"name": "偶遇(鲁豫时隔15年全新作品集)", "publish": "北京十月文艺出版社", "price": 19.5}
{"name": "一一风荷举", "publish": "作家出版社", "price": 14.0}
{"name": "野火集:三十周年纪念版", "publish": "广西师范大学出版社", "price": 21.8}
{"name": "雅舍谈吃--梁实秋散文经典系列,插图珍藏版", "publish": "湖南文艺出版社", "price": 13.3}
{"name": "泥步修行", "publish": "长江文艺出版社", "price": 25.8}
{"name": "没有一种生活是可惜的(继《活着》之后,余华再论人生与自我)(当当专享签章本,余华首部精装四色散文集)", "publish": "陕西师范大学出版社", "price": 28.4}
{"name": "八九十枝花", "publish": "北京十月文艺出版社", "price": 24.5}
{"name": "余光中下次你路过,人间已无我", "publish": "江西人民出版社", "price": 18.3}
{"name": "小飞机,欧洲行(毕淑敏环球史诗旅行2019全新创作)", "publish": "湖南文艺出版社", "price": 29.0}
{"name": "愿你喜欢被岁月修改的自己", "publish": "北京联合出版有限公司", "price": 23.3}
{"name": "名家文丛—白洋淀纪事(平装)", "publish": "人民日报出版社", "price": 18.8}
{"name": "走到人生边上——自问自答(增订本)(碎金文丛)", "publish": "商务印书馆", "price": 24.5}
{"name": "山川岁月长:蒋勋、林清玄等文学大师与一代人的对话", "publish": "江苏凤凰文艺出版社", "price": 23.7}
{"name": "成长,请带上这封信(韩寒、刘瑜写给孩子的信,内含刘瑜《愿你慢慢长大》,央视《朗读者》第1期张梓琳感动朗读))", "publish": "人民文学出版社", "price": 19.0}
{"name": "世间所有相遇 都是久别重逢(全新升级版)", "publish": "湖南文艺出版社", "price": 18.9}
{"name": "你是我不及的梦(三毛全新散文集,26篇散佚作品,大陆首度结集出版)", "publish": "北京十月文艺出版社", "price": 14.7}
{"name": "史铁生散文精选(名家散文典藏·彩插版)", "publish": "长江文艺出版社", "price": 22.7}
{"name": "不畏将来 不念过去2(百万女人的枕边书。畅销两百万册《不畏将来 不念过去》第二部升华上市,超越第一部的全新作品!)", "publish": "浙江文艺出版社", "price": 21.0}
{"name": "干校六记(精装新版)", "publish": "生活·读书·新知三联书店", "price": 16.9}
{"name": "禅与极简生活艺术", "publish": "北京时代华文书局", "price": 18.4}
{"name": "两地书(鲁迅写给自己的真实之作 )", "publish": "江苏凤凰文艺出版社", "price": 15.3}
{"name": "林徽因:不慌不忙的坚强", "publish": "哈尔滨出版社", "price": 13.15}
{"name": "寻觅中华", "publish": "作家出版社", "price": 19.0}
{"name": "病隙碎笔:插图珍藏2019版", "publish": "湖南文艺出版社", "price": 24.9}
{"name": "冯唐诗百首(冯唐首部现代诗集/打造不一样的“唐诗百首”/全新序言 精装升级/高晓松、李银河、柴静、李敬泽推荐)", "publish": "天津人民出版社", "price": 25.5}
{"name": "以自己喜欢的方式过一生(真正的平静,不是避开车马喧嚣,而是在心中修篱种菊)", "publish": "江苏文艺出版社", "price": 15.6}
{"name": "人生终要有一场触及灵魂的旅行(新版)", "publish": "湖南文艺出版社", "price": 20.4}
{"name": "梁实秋:人间意趣(老树画画全彩插画,梁实的生活智慧散文精装收藏本)", "publish": "天津人民出版社", "price": 19.2}
{"name": "纸上的故宫", "publish": "长江文艺出版社", "price": 23.4}
{"name": "康辉:平均分(当当专享100%亲笔签名+印签版书法)", "publish": "长江文艺出版社", "price": 34.8}
{"name": "八千里路云和月(白先勇重磅新作!这是他的人生感悟,更是填不满的文化乡愁。章诒和、余秋雨、林青霞盛赞)", "publish": "中国友谊出版公司", "price": 24.7}
{"name": "生命因你而火热(“新裤子乐队”彭磊、庞宽首部随笔集。随书附赠明信片)", "publish": "民主与建设出版社", "price": 33.8}
{"name": "康辉:平均分(当当印签版书法)", "publish": "长江文艺出版社", "price": 34.8}
{"name": "愿有人陪你颠沛流离(畅销五年全新增订版,装帧升级,新增概念内插以及万字全新章节!张嘉佳、刘同、素黑诚意推荐!)", "publish": "北京联合出版有限公司", "price": 23.4}
{"name": "天青色等烟雨(方文山新书,当当独家方文山亲笔签名版+签章版)", "publish": "湖南文艺出版社", "price": 22.9}
{"name": "万物有灵 贾平凹的生命思索课(免费送印章书法,三款国画藏书票,《朗读者》董卿含泪推荐,比《自在独行》更经典)", "publish": "长江文艺出版社", "price": 21.6}
{"name": "浆糊梦", "publish": "北京联合出版有限公司", "price": 16.4}
{"name": "独居冰岛的一年", "publish": "天津人民出版社", "price": 44.2}
{"name": "十点读书日历2020", "publish": "浙江文艺出版社", "price": 98.0}
{"name": "我可能得抑郁症了!", "publish": "四川文艺出版社", "price": 28.9}
{"name": "远村行走:寻访中国最后的山村(当当尊享作者亲笔签名本+随书附赠精美四联书签。贾平凹、比尔·波特倾情推荐!)", "publish": "百花洲文艺出版社", "price": 34.3}
{"name": "丰子恺万般滋味,都是生活(精装典藏版)", "publish": "华中科技大学出版社", "price": 34.9}
{"name": "季羡林的人生智慧4册套装(金庸、贾平凹、梁文道、钱文忠、白岩松、林青霞推荐)", "publish": "江苏凤凰文艺出版社", "price": 90.0}
{"name": "认得几个字(2019新版)", "publish": "广西师范大学出版社", "price": 40.3}
{"name": "遇见名家经典 不疯魔,不成活 刘墉精装全彩4色 限量签名印章版", "publish": "台海出版社", "price": 25.0}
{"name": "我的精神家园", "publish": "北京十月文艺出版社", "price": 19.5}
{"name": "我心咫尺,时或远方", "publish": "化学工业出版社", "price": 32.3}
{"name": "这些人,那些事", "publish": "译林出版社", "price": 22.1}
{"name": "相逢如初见 回首是一生(当当独家签名版)", "publish": "湖南文艺出版社", "price": 19.5}
{"name": "简单 甚好(丰子恺的人生哲学)", "publish": "江苏凤凰文艺出版社", "price": 26.3}
{"name": "季羡林散文精选集:糊涂一点,潇洒一点(金庸、白岩松、钱文忠、林青霞等极力推崇)", "publish": "天津人民出版社", "price": 26.2}
{"name": "一朵云推动另一朵云", "publish": "新星出版社", "price": 30.2}
{"name": "嘿,三十岁", "publish": "江苏文艺出版社", "price": 23.0}
{"name": "巴金散文精选(名家散文典藏·彩插版)", "publish": "长江文艺出版社", "price": 20.8}
{"name": "哥伦比亚的倒影【理想国】", "publish": "广西师范大学出版社", "price": 18.7}
{"name": "走夜路请放声歌唱", "publish": "新星出版社", "price": 22.5}
{"name": "你是那人间的四月天:一身诗意千寻瀑,万古人间四月天", "publish": "山东文艺出版社", "price": 14.0}
{"name": "悲喜自渡:季羡林的孤独智慧(TFboys王源认同的生活态度)", "publish": "江苏凤凰文艺出版社", "price": 21.4}
{"name": "雅舍谈吃(2019线装典藏版,完整辑录梁实秋96篇令人馋涎欲滴的谈吃美文)", "publish": "上海文艺出版社", "price": 19.5}
{"name": "文化苦旅 2019修订本(30周年纪念版,文化导师余秋雨开山之作,热销千万册)", "publish": "长江文艺出版社", "price": 35.86}
{"name": "我执", "publish": "广西师范大学出版社", "price": 18.7}
{"name": "三十六大(冯唐畅销杂文集/全新序言 精装升级/新增36幅冯唐私人摄影作品/高晓松、李银河、柴静、李敬泽推荐)", "publish": "浙江文艺出版社", "price": 24.0}
{"name": "文化苦旅", "publish": "长江文艺出版社", "price": 38.8}
{"name": "我的阿勒泰(李娟 名家散文经典 精装美绘版)", "publish": "长江文艺出版社", "price": 24.0}
{"name": "人生若只如初见(增订版)——古典诗词的美丽与哀愁", "publish": "人民文学出版社", "price": 18.0}
{"name": "得未曾有(安妮宝贝更名“庆山”后首发新作)", "publish": "北京十月文艺出版社", "price": 26.7}
{"name": "给孩子的散文", "publish": "中信出版社", "price": 22.0}
{"name": "四时之美:丰子恺节令书", "publish": "长江出版社", "price": 34.3}
{"name": "宗璞散文精选(名家散文典藏·彩插版)", "publish": "长江文艺出版社", "price": 18.2}
{"name": "你来人间一趟,你要发光发亮", "publish": "江苏凤凰文艺出版社", "price": 17.1}
{"name": "丁立梅的写作课:套装三册", "publish": "东方出版社", "price": 69.0}
{"name": "迟子建散文系列:我的世界下雪了", "publish": "浙江文艺出版社", "price": 17.4}
{"name": "恋爱的犀牛", "publish": "湖南文艺出版社", "price": 26.6}
{"name": "努力,是为遇见更好的自己", "publish": "时代文艺出版社", "price": 19.0}
{"name": "贾平凹散文精选(名家散文典藏·彩插版)", "publish": "长江文艺出版社", "price": 23.4}
{"name": "守望的距离(新版)", "publish": "浙江人民出版社", "price": 31.2}
{"name": "冯骥才散文精选(名家散文典藏·彩插版)", "publish": "长江文艺出版社", "price": 19.5}
{"name": "中国文脉 2019年修订本(《文化苦旅》后余秋雨珍视的总结之作)", "publish": "长江文艺出版社", "price": 49.0}
{"name": "万人如海一身藏(独木舟新书)", "publish": "湖南文艺出版社", "price": 24.0}
{"name": "将饮茶(精装新版)", "publish": "生活·读书·新知三联书店", "price": 19.8}
{"name": "我们的老院(2017年中国好书)", "publish": "北京十月文艺出版社", "price": 28.0}
{"name": "常识与通识", "publish": "江苏文艺出版社", "price": 25.7}
{"name": "雪小禅新书 惜君如常", "publish": "江苏文艺出版社", "price": 16.1}
{"name": "幸福了吗?(新版)", "publish": "长江文艺出版社", "price": 23.8}
{"name": "季羡林散文精选(名家散文典藏·彩插版)", "publish": "长江文艺出版社", "price": 19.5}
{"name": "赵桥村", "publish": "广西师范大学出版社", "price": 29.2}
{"name": "边缘信使(轰动全球的美国版《看见》!荣获9座艾美奖、CNN传奇安德森·库珀首度剖析15年“看见”世界的心灵史。)", "publish": "北京联合出版有限公司", "price": 38.7}
{"name": "蔡澜三部曲:不如任性过生活+愿你成为最好的女子+今天也要好好吃饭(全三册套装)", "publish": "北京时代华文书局有限公司", "price": 48.3}
{"name": "汪曾祺小说集(2019新版!《受戒》《异秉》《大淖记事》等汪曾祺经典小说二十一部全收录,特别辑录《〈聊斋〉新义》十一篇", "publish": "江西人民出版社", "price": 27.5}
{"name": "我承认我不曾历经沧桑", "publish": "广西师范大学出版社", "price": 20.8}
{"name": "席慕容散文·槭树下的家", "publish": "长江文艺出版社", "price": 18.2}
{"name": "不知有花—张晓风执笔50周年纪念版", "publish": "北京联合出版有限公司", "price": 22.8}
{"name": "常识", "publish": "广西师范大学出版社", "price": 28.5}
{"name": "幼稚园 今日宜远游(筹备三年,韩寒再创文艺品牌「幼稚园」。我还年轻,我渴望上路。)", "publish": "浙江文艺出版社", "price": 24.9}
{"name": "马燕日记(2015新版)", "publish": "江苏文艺出版社", "price": 16.8}
{"name": "我和连岳一起成长", "publish": "四川文艺出版社", "price": 24.0}
{"name": "一个人的村庄(第十届茅盾文学奖入围作家刘亮程作品;以巫术般有能量的文字,带每个人回归自然、认领故乡;多篇入选小学及中学", "publish": "江西人民出版社", "price": 34.0}
{"name": "世界很小,而你刚好发光", "publish": "江苏文艺出版社", "price": 25.7}
{"name": "羊道三部曲(套装全3册)", "publish": "中信出版社", "price": 85.0}
{"name": "我们生活在巨大的差距里(余华十年首部杂文集)", "publish": "北京十月文艺出版社", "price": 17.5}
{"name": "请至少爱一个像男人的男人(张小娴2017年新书)", "publish": "湖南文艺出版社", "price": 19.9}
{"name": "丁立梅散文精选(名家散文典藏·彩插版)", "publish": "长江文艺出版社", "price": 19.5}
{"name": "人生幸好有别离:林清玄", "publish": "长江文艺出版社", "price": 28.8}
{"name": "子夜:茅盾诞辰120周年纪念版", "publish": "江苏科学技术出版社", "price": 14.9}
{"name": "朗读者 第一辑", "publish": "人民文学出版社", "price": 41.0}
{"name": "我与父辈(2019新版,独家收录阎连科最新自序《被我走丢了的家》。一次自我救赎,一趟精神上的返乡之旅。)", "publish": "河南文艺出版社", "price": 20.6}
{"name": "中国文脉 软精装", "publish": "长江文艺出版社", "price": 33.1}
{"name": "此生未完成(精)", "publish": "湖南科技出版社", "price": 26.4}
{"name": "张晓风散文精选(名家散文典藏·彩插版)", "publish": "长江文艺出版社", "price": 19.5}
{"name": "只有岁月不我欺", "publish": "长江文艺出版社", "price": 24.0}
{"name": "林夕:任你行", "publish": "四川文艺出版社", "price": 19.7}
{"name": "故宫的古物之美·绘画风雅1", "publish": "人民文学出版社", "price": 52.2}
{"name": "南极之南(毕淑敏2018新书)", "publish": "湖南文艺出版社", "price": 28.0}
{"name": "优雅(修订版) (中国“时尚女魔头”的优雅心经,白百何、范冰冰、李冰冰、孙俪、姚晨等众星推荐)", "publish": "新星出版社", "price": 19.5}
{"name": "林清玄作品:心外无物 随遇而安", "publish": "线装书局", "price": 29.8}
{"name": "生命是孤独的旅程", "publish": "中国友谊出版公司", "price": 23.8}
{"name": "雨Hujan", "publish": "四川人民出版社", "price": 24.7}
{"name": "私城记", "publish": "江苏凤凰文艺出版社", "price": 25.7}
{"name": "蔡澜说美食:学会浅尝二字(美食家蔡澜关于吃的哲学,吃少一点,吃好一点,学会浅尝二字。有灵性的人,从食物中也能悟出道理)", "publish": "北京时代华文书局", "price": 23.1}
{"name": "汪曾祺图文作品集套装共4册:人间有味+人间小暖+人间有趣+人间草木", "publish": "天津人民出版社", "price": 58.5}
{"name": "你最好的样子就是做自己", "publish": "北京联合出版有限公司", "price": 34.4}
{"name": "可爱的中国(2018未删节精装典藏版,与瞿秋白《多余的话》齐名,梁晓声、张颐武推荐)", "publish": "中国友谊出版公司", "price": 19.9}
{"name": "我把活着欢喜过了(梁实秋的生活智慧)", "publish": "江苏凤凰文艺出版社", "price": 23.7}
{"name": "生活明朗 万物可爱:季羡林的豁达智慧(蔡徐坤等年轻人一读再读的成长经典)", "publish": "江苏凤凰文艺出版社", "price": 21.4}
{"name": "雅活书系·不器:我只是个生活家", "publish": "广西师范大学出版社", "price": 36.4}
{"name": "一定要,爱着点什么:汪曾祺散文精选集,20周年精装纪念版。人生如梦,我投入的却是真情。", "publish": "百花洲文艺出版社", "price": 29.0}
{"name": "我们始终独自行走在这个世界", "publish": "百花洲文艺出版社", "price": 23.4}
{"name": "今晚月色好美(当当独家签名版)", "publish": "湖南文艺出版社", "price": 20.4}
{"name": "汪曾祺图文珍藏版精装套装全三册:人间草木,人间滋味,人间有戏", "publish": "天津人民出版社", "price": 40.7}
{"name": "不必交谈的时刻(肖战、华晨宇诚意推荐)", "publish": "重庆出版社", "price": 24.8}
{"name": "有一天,他们老了(苏青、月关、欧阳慧三人签章版)", "publish": "江苏凤凰文艺出版社", "price": 27.4}
{"name": "林夕:原来你非不快乐(全新修订版)", "publish": "四川文艺出版社", "price": 19.7}
{"name": "不争论的智慧:王蒙经典散文(精装)(“人民艺术家”国家荣誉称号获得者王蒙,2019新作)", "publish": "陕西师范大学出版社", "price": 28.4}
{"name": "痛并快乐着(新版)", "publish": "长江文艺出版社", "price": 23.8}
{"name": "醒来觉得甚是爱你", "publish": "湖南文艺出版社", "price": 23.7}
{"name": "无端欢喜(诗人余秀华的首部散文集)", "publish": "新星出版社", "price": 19.5}
{"name": "生死之间:当我们与疾病和死亡狭路相逢", "publish": "中信出版社", "price": 36.5}
{"name": "不如任性过生活", "publish": "北京时代华文书局", "price": 16.1}
{"name": "煮酒探西游(新版)", "publish": "民主与建设出版社", "price": 19.0}
{"name": "老舍散文集:微笑深处 最是孤独", "publish": "北京理工大学出版社", "price": 22.7}
{"name": "思维的乐趣", "publish": "中国人民大学出版社", "price": 14.8}
{"name": "汪曾祺图文作品集套装共4册:人间有味+人间小暖+人间有趣+人间草木", "publish": "天津人民出版社", "price": 91.8}
{"name": "林清玄精装散文集(全七册)", "publish": "北京联合出版公司", "price": 139.3}
{"name": "湘行散记及其他 先锋经典文库", "publish": "陕西师范大学出版社", "price": 12.0}
{"name": "你心柔软,却有力量--林清玄最新散文精选", "publish": "长江文艺出版社", "price": 18.9}
{"name": "百所名校校长推荐:敬畏生命(当代十大散文家张晓风写给孩子的文学书)", "publish": "北京联合出版有限公司", "price": 20.0}
{"name": "毕淑敏散文精选(名家散文典藏·彩插版)", "publish": "长江文艺出版社", "price": 23.4}
{"name": "林清玄经典散文集:心无挂碍,无有恐惧(林清玄执笔45年禅意散文代表作)", "publish": "江苏文艺出版社", "price": 24.7}
{"name": "快乐的人,都有温润的趣味", "publish": "青岛出版社", "price": 29.5}
{"name": "趋光运动:回溯童年的精神图景", "publish": "湖南文艺出版社", "price": 34.8}
{"name": "鲁迅全集(1-18卷)", "publish": "人民文学出版社", "price": 1074.4}
{"name": "愿有人待你如初:细品红楼梦中人(当当专享签名本)", "publish": "北京联合出版公司", "price": 12.0}
{"name": "旧日的静定(签名本)", "publish": "山东画报出版社", "price": 34.0}
{"name": "青苔不会消失", "publish": "中信出版社", "price": 28.3}
{"name": "行走的耳朵", "publish": "广西师范大学出版社", "price": 27.0}
{"name": "尽头是你,世界荒芜也不畏惧(2019精装新版)", "publish": "天津人民出版社", "price": 12.0}
{"name": "史铁生精选套装(我与地坛:插图版+我的遥远的清平湾:插图版+夏天的玫瑰:插图版+放下与执着:插图版)", "publish": "湖南文艺出版社", "price": 117.9}
{"name": "文化苦旅 软精装 (1-9年级必读书单)", "publish": "长江文艺出版社", "price": 33.1}
{"name": "凡心所向,素履所往:季羡林的生命智慧(《榜样阅读》蔡徐坤品读推荐)", "publish": "江苏凤凰文艺出版社", "price": 21.4}
{"name": "此生遇你已很美:有一种深情叫友情", "publish": "武汉出版社", "price": 48.8}
{"name": "所有的遗憾都是成全(生活中遇到的不完美与不平衡都是人生最好的启蒙,就如同乌云与暴风雨是天空最好的启示一般。)", "publish": "北京联合出版公司", "price": 20.0}
{"name": "穗子的动物园", "publish": "人民文学出版社", "price": 29.0}
{"name": "中国最美散文", "publish": "江苏美术出版社", "price": 8.3}
{"name": "游戏人间(选编贾平凹名篇《写给母亲》,央视《朗读者》节目斯琴高娃动情朗读。看贾平凹如何洗涤人生烦恼,从三劫四劫中获得生", "publish": "百花洲文艺出版社", "price": 20.0}
{"name": "老舍散文精选(名家散文典藏·彩插版)", "publish": "长江文艺出版社", "price": 19.5}
{"name": "龙应台人生三书全3册套装龙应台目送龙应台孩子你慢慢来亲爱的安德烈龙应台作品全集龙应台散文集", "publish": "广西师范大学出版社", "price": 51.0}
{"name": "二条十年(1955—1964,荣获深圳读书月2019年度十大文学好书)", "publish": "中华书局", "price": 39.2}
{"name": "朱生豪情书全集(手稿珍藏本)", "publish": "中国青年出版社", "price": 46.2}
{"name": "周迅 : 自在人间", "publish": "上海人民出版社", "price": 52.8}
{"name": "心灵的归途(精选收录沈从文、丰子恺、梁实秋、贾平凹等几十位知名作家的经典散文!愿每个内心孤独焦躁的人能得到安宁的抚慰", "publish": "天津人民出版社", "price": 27.4}
{"name": "我的精神家园", "publish": "中国人民大学出版社", "price": 11.8}
{"name": "生活是很好玩的", "publish": "北京时代华文书局", "price": 19.7}
{"name": "醒客的世界", "publish": "北京十月文艺出版社", "price": 22.5}
{"name": "我们这个时代的怕和爱", "publish": "中国文联出版社", "price": 19.9}
{"name": "你的人生,还有10001种可能", "publish": "北京日报出版社(原同心出版社)", "price": 21.0}
{"name": "罗马(首位获意大利“罗马文学奖”的华人作家、诗人虹影,回归新作。)", "publish": "重庆出版社", "price": 45.0}
{"name": "万物有情", "publish": "北京联合出版有限公司", "price": 31.1}
{"name": "活着,不着急", "publish": "中信出版社", "price": 36.5}
{"name": "向往的生活(精选汪曾祺、丰子恺、莫言等几十位知名作家的经典散文!心之所向素履以往。希望每个人能于喧嚣中寻到生活的真意)", "publish": "天津人民出版社", "price": 27.4}
{"name": "威尼斯日记", "publish": "江苏文艺出版社", "price": 19.0}
{"name": "诺贝尔文学奖泰戈尔代表作 园丁集 中英双语冰心名译全彩4色", "publish": "台海出版社", "price": 19.9}
{"name": "故宫(精装四色)", "publish": "工人出版社", "price": 46.8}
{"name": "琦君散文(名家散文典藏·彩插版)", "publish": "长江文艺出版社", "price": 19.3}
{"name": "君子之道", "publish": "北京联合出版公司", "price": 22.8}
{"name": "画见(签章本)", "publish": "上海人民出版社", "price": 57.8}
{"name": "知道分子", "publish": "北京十月文艺出版社", "price": 17.5}
{"name": "林清玄散文精选.青少卷", "publish": "长江文艺出版社", "price": 18.2}
{"name": "迟子建散文", "publish": "浙江文艺出版社", "price": 14.0}
{"name": "汪曾祺散文精选——名家散文经典", "publish": "长江文艺出版社", "price": 16.9}
{"name": "岁华一枝:京都读书散记(精)", "publish": "中华书局", "price": 48.3}
{"name": "厚积落叶听雨声", "publish": "江苏文艺出版社", "price": 18.9}
{"name": "汪曾祺作品套装2册:人间有味+人间草木", "publish": "北京时代华文书局", "price": 36.7}
{"name": "周国平散文精选——名家散文经典", "publish": "长江文艺出版社", "price": 19.5}
{"name": "做一个有境界的女子:不自轻,不自弃", "publish": "青岛出版社", "price": 18.1}
{"name": "旷代的忧伤", "publish": "江苏人民出版社", "price": 16.9}
{"name": "旅行与读书", "publish": "中信出版社", "price": 30.8}
快速添加数据的小脚本
Copy
# tests.py

import os
import json

import django
# 在manage.py查看这个名字
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "项目名.settings")
django.setup()

from api.models import Book

with open('book_info.json', 'r', encoding='utf-8') as f:
    books = [Book(**json.loads(line.strip())) for line in f]

Book.objects.bulk_create(books)

# 这里数据添加进去了,就说明主从已经基本配置成功了。

6 编写视图与路由#

urls.py

Copy
from django.conf.urls import url
from django.contrib import admin
from api import views

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^test/', views.TestAPIView.as_view()),
]

views.py

Copy
from rest_framework.serializers import ModelSerializer
from rest_framework.generics import ListAPIView

from . import models


class BookModelSerializer(ModelSerializer):
    """序列化类"""
    class Meta:
        model = models.Book
        fields = '__all__'


class TestAPIView(ListAPIView):

    serializer_class = BookModelSerializer
    queryset = models.Book.objects.all()

上面使用到了drf, 别忘了在settings的app配置项里面添加rest_framework.

7 测试#

在浏览器中输入对应地址, 可以看到结果成功出来了。

三、参考#

  1. https://blog.csdn.net/xfcy1990/article/details/88953248
  2. 官网

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

强烈推荐

高性能SSD云服务器ECS抗攻击,高可用云数据库RDS