<p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-13b06998c4da2c95.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><h1><strong>内容简介</strong></h1><p>本文内容为该项目V1.0版本的内容。
</p><p>Django搭建康养智慧中医项目平台服务的 <strong>新闻资讯</strong> 应用API开发配置、Xadmin后台设置管理和数据流API的实现,根据实际情况和具体需求进行修改该即可。</p><h1><strong>应用创建&配置</strong></h1><p><strong>1.创建应用</strong> </p><p>进入文件根目录执行CMD命令创建新闻资讯应用,并将创建好的应用文件夹移动到目录的apps下即可。</p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-d087c4a54a0c7d5e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>2.配置新闻应用模块</strong> </p><p>在settings.py文件中修改</p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-152e4addb6a066ab.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>3.不需要修改该的文件</strong> </p><ul><li><p><strong>admin.py</strong> 这个我们使用xadmin代替的原有版本的admin,因此这个文件不需要修改该。</p></li><li><p><strong>apps.py</strong> 应用的配置文件,不需要动 。</p></li><li><p><strong>test.py</strong> 测试执行脚本,不需要动。</p></li></ul><p>用于定义我们数据库中存储表单的表单内容,其中包括表单名和字段信息。</p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-be3410817e4a09d3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p/><h1><strong>应用 models.py</strong></h1><p><strong>1.文章的类别</strong>
</p><p>用于定义文章大类类别,API接口传输文章的一级类别显示在主页。</p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-bf4aef432645fdb9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>2.文章的栏目</strong> </p><p>用于定义文章二级栏目,与文章的一级类别形成外键关联关系,在Web前端展示形式为下拉式菜单。</p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-2496166b22442a1f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>3.文章Tag标签</strong> </p><p>用于定义文章tag标签类别,设计Tag标签快速检索功能使用。</p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-1cb8b1dd922e5209.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>4.文章基本信息</strong> </p><p>定义文章的基本信息,除了文章的详情内容以外文章的全部信息在这里进行定义。</p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-3285692be7a5fc71.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>5.文章详细内容</strong> </p><p>定义文章详情,与文章详情通过slug字段进行关联查询。</p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-885f88b30aef4307.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>6.拼接文章基本信息和正文</strong> </p><p>在Xadmin后台使用新建model的方式进行不同业务模块内容的拼接,通过两个model共有的字段进行拼接。</p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-63d22b07888806d8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>7.主页展示数据</strong> </p><p>构建主页数据缓存文章列表数据,为了是提升访问速度,通过定时任务定时更新该表单数据,效果为主页数据更新即变化。</p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-247c97dc231d9f0c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>9.各个频道展示数据</strong> </p><p>构建二级栏目数据缓存文章列表数据,为了是提升访问速度,通过定时任务定时更新该表单数据,效果为二级栏目数据更新即变化。</p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-a22be5fd0c493850.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>10.执行命令行生成数据库表单</strong> </p><p>每次改动model文件都需要执行一次,让新的设置生效并更新数据库字段。</p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-d43d7a7ccfd7398b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>11.查看mysql数据仓库会生成对应的表单</strong> </p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-b41a6ceb6c0ea35e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><h1><strong>应用 adminx.py</strong></h1><p>用于在后台展示models.py中定义的内容在后台实现增删改查功能 其中关闭一些不必要的功能和自定义一些需要使用的功能内容</p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-5adc1c8add9f9627.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>1.文章内容的类别表单</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-c72a6a7dad7fe3c0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>2.文章内容的栏目表单</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-dc32b1aba446c077.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>3.文章Tag标签表单</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-e2f23c7abbc6d386.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>4.文章内容基础信息表单</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-a58a4a5d25d76628.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>5.文章内容详情信息表单</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-20792c6f14693677.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>6.文章内容全部信息表单</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-2f6fdd006db73746.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>7.首页内容信息表单</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-21739550af5a98a2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>8.二级栏目的信息表单</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-5c70d34f6e9d44f5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>9.注册Xadmin</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-da88378dc72ea2a5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><h1><strong>数据流 serilaizes.py</strong></h1><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-1147d8b0a6e596b0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p>这里通过控制fields内容API接口流可以展示的字段信息,内容定义的基本模板大致这样</p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-2a80cf2c9be25a21.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>1.继承user类Serilaizes</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-551eea237973a243.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>2.文章大类分类Serilaizes</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-89d073f9818db47b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>3.文章栏目分类Serilaizes</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-f313abe8f26a8a24.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>4.文章标签tag的Serilaizes</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-bd9d34154a7579e0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>5.文章基础信息Serilaizes</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-9c540304a52cad08.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>6.文章详情信息Serilaizes</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-9e40751693bada1e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>7.主页文章内容Serilaizes</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-de5a95305f9f0ce7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>8.各二级栏目文章内容Serilaizes</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-79aa5ecbda1e2941.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><h1><strong>过滤流 myfilter.py</strong></h1><p>流式数据进行过滤的自定义方法,为了有选择性的传输数据使用,未来会在文章相关处理使用到这里先简单写一下。
</p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-3505788fadbd785a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>1.自定义过滤文章信息</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-98eacbdd866152fb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>2.自定义过滤可以检索内容</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-af2e34ac26231d79.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>3.自定义过滤主页可以检索的内容</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-fcd4ebafc374dc6c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>4.自定义过滤频道可以检索的内容</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-ea0281fd0223de81.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><h1><strong>视图 Views.py</strong></h1><p>通过Views视图的方式实现数据读取和流式传输。
</p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-d048296a83d498e2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p class="image-package"><strong>1.实现翻页的功能</strong> </p><p>这里如果不做翻页设置的话会密密麻麻的塞满整个屏幕的数据。</p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-63ce747c846a7067.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>2.新闻大类分类</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-8b0dfc3ac2dc86d7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>3.新闻二级栏目分类</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-27665989f3627915.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>4.新闻Tag标签</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-4fd91e3c957fd482.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>5.文章的基本信息</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-9e2dce277ff70dc9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>6.文章的详情信息</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-c2a2643ed4088ae5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>7.主页的文章信息</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-f96be169ffadadf9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>8.各类别的的文章信息</strong></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-13ff0f45831cde83.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><h1><strong>配置 url.py</strong></h1><p>实现路由设置。
</p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-118d1e33a050c649.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p>这里通过 <strong>rest_framework</strong> 构建API接口</p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-8b3119b066d4ae94.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><h1><strong>应用部分展示</strong></h1><p>配置完毕之后,打开CMD命令行执行。
</p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-d8bed3170c5ca2bc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p><strong>1.xadmin后台展示</strong> </p><p>展示内容需要在Xadmin中进行配置,所有配置均在home内容里可以看到浏览器打开 http://127.0.0.1/xadmin,用创建的用户名和密码登陆会看到。</p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-570808c604ec81e9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-ee12c5817f06a8b0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-dab6a0887601ed62.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p>
</p><p>swagger应用后展示结果。</p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-b2f569f0aa49a071.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p>
</p><p>这里构建的数据流是配合web前端展示的内容。</p><p class="image-package"><img class="uploaded-img" src="https://upload-images.jianshu.io/upload_images/24367109-8d94d9f6f85e63e8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="auto" height="auto"/></p><p>
</p>
「基于Python技术的智慧中医商业项目」Django后端新闻应用设计
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 内容简介 本文内容为该项目V1.0版本的内容。 Django搭建康养智慧中医项目平台服务的系统配置内容,根据...
- 内容简介 本文内容为该项目V1.0版本的内容。 基于Django前后端分离项目的前端Web网站展示。由于时间...
- 内容简介 本文内容为该项目V1.0版本的内容。 本章节进行前后端分离项目的后台数据API接口内容的部分示。由...
- 内容简介 本文内容为该项目V1.0版本的内容。 介绍整体项目使用的技术模块和系统搭建思路。 技术模块 ...
- 内容简介 本文内容为该项目V1.0版本的内容。 中医问诊系统第一版系统前后台展示内容。 展示页面 ...