「基于Python技术的智慧中医商业项目」Django后端新闻应用设计

<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>

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,670评论 5 460
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,928评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,926评论 0 320
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,238评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,112评论 4 356
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,138评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,545评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,232评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,496评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,596评论 2 310
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,369评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,226评论 3 313
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,600评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,906评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,185评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,516评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,721评论 2 335

推荐阅读更多精彩内容