When the epidemic strikes, learn to develop and deploy the visualization website of epidemic situation with Python in 30 minutes

osc_ sqtwbty4 2021-01-23 12:44:12
epidemic strikes learn develop deploy


The epidemic is coming , We stay at home It's better to learn to use python How to develop and deploy a real-time epidemic tracking visualization page , You can also customize the visualization charts for your hometown . Let's see the effect first

 picture Home rendering  picture


 picture

 picture Data query rendering  picture

 picture

You can see , It can realize data visualization , It can also realize data query and other functions . The key is that the fastest way from development to deployment is as long as 30 It'll be online in a few minutes ! Let's start .







Get ready

  • [「 must 」] Set up a server and configure it anaconda And mysql. If you don't have a server, you can see my previous article about purchasing and configuring your own cloud server

  • A computer and configure it mysql. You can read the previous article centos How to configure mysql

  • Basic programming knowledge

  • Software :navicat、filezilla ( All the previous articles have introduced )

  • python relevant :requests( Data crawling )、pyecharts( Data visualization )、Django


Start

The requirements of this development are very clear , In short, it's three steps

  • Crawl data

  • Data visualization

  • Deploy the visualized results to the server

Well, the first two steps above can turn to my previous articles , How to get data from the Internet and make use of pyecharts Visualizing . So I assume you've written a visual program , In the use of pyecharts At the end of Visualization , Use

.render('map1.html')# Translate the picture into html Format The name is map1.html

The map we need to show 、 Pie charts and so on are born into html Format saved , It is convenient for us to embed it into the web page later . Then give it to 「Django」 Well .

install Django And the required modules

First, execute the following code installation on the server side Django And database related modules

# install Django
pip install django
# Database related modules , It doesn't matter if it's wrong
pip install pymysql
pip install mysqlclient



Because we're using mysql, So in the back Django There will be an error in one step of the synchronization database , Because it's rapid deployment , We directly modify the relevant documents in advance to solve the error . use filezilla Connect to your remote server , If you follow the configuration in my article anaconda Words , Open the following path

/root/anaconda3/lib/python3.7/site-packages/django/db/backends/mysql

find base.py Note the following

if version < (1, 3, 13):
raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)

Then open the... In this folder operations.py, modify 146 Row or so , hold decode Change it to encode

query = query.decode(errors='replace')

After completing the above two steps, transfer the modified file to the original folder .

To configure Django

Now? ssh Connect to your server , After installation Django after , Execute the following code :

django-admin startproject djtest

It means to create a project called djtest Of Django project , If nothing else , stay filezilla If you refresh the directory in, you will have one more folder for djtest, And then execute cd djtest Go to this folder , Re execution python manage.py startapp web Then refresh the folder , There will be one more web Folder . Under normal circumstances , You need to check the... In the folder settings.py And other related configuration files ( Contains database configuration 、 Form settings 、 Page registration, etc ), The process is relatively complex , So you don't need to configure it for the time being .
「 Official account : Get up early python reply Django Get the whole configured folder 」 Upload the whole file directly to the server to cover it djtest Folder .

But it's not completely lazy , Still need you to complete a few steps ,

  • After the overlay is completed, you need to download the settings.py file , Modify the password of the database to the password you set before configuring the database . And then upload it to cover the original .

  • take static In folder map1.html,mp2.html Replace it with the one you just generated for your area of interest html File overlay upload .

 picture

Then use navicat Connect to your own remote database , Follow these steps to create one called djtest The database of

 picture

After performing .

python manage.py migrate

thus , Already completed 99% 了 , Just one last step away , perform

nohup python manage.py runserver 0.0.0.0:8000 &

Then go to Alibaba cloud and follow the method mentioned in the previous article , take 8000 Add the port to the security group .

here , Find a browser to input your ip:8000, You can successfully see the website you deployed , So how to further personalize the website ( Add login module 、 Add and modify charts 、 Add and modify text ) Or want to achieve other functions , You can pay attention to the following articles of the official account . At least come here , You've developed your own epidemic data tracking website .

 picture


版权声明
本文为[osc_ sqtwbty4]所创,转载请带上原文链接,感谢
https://pythonmana.com/2021/01/20210123123954603x.html

  1. Mandatory conversion of Python data type
  2. Django reported an error: 'key' ID 'not found in' xxx '. Choices are: xxx'
  3. Python 400 sets of large video, starting from the right direction to learn, a complete set to you
  4. 只需十四步:从零开始掌握Python机器学习(附资源)
  5. Just 14 steps: Master Python machine learning from scratch (resources attached)
  6. Python|文件读写
  7. 安利一个Python界神奇得网站
  8. Python | file reading and writing
  9. Amway is a marvelous website in Python world
  10. 第二热门语言:从入门到精通,Python数据科学简洁教程
  11. The second popular language: from introduction to mastery, python data science concise tutorial
  12. 以我的亲身经历,聊聊学python的流程,同时推荐学python的书
  13. With my own experience, I'd like to talk about the process of learning Python and recommend books for learning python
  14. 以我的亲身经历,聊聊学python的流程,同时推荐学python的书
  15. With my own experience, I'd like to talk about the process of learning Python and recommend books for learning python
  16. Django url 路由匹配过程
  17. Django URL routing matching process
  18. 强者一出,谁与争锋?与Python相比,C++的运行速度究竟有多快?
  19. Who will fight against the strong? How fast is C + + running compared with Python?
  20. python 学习体会
  21. Experience of learning Python
  22. python7、8章
  23. Chapter 7 and 8 of Python
  24. python bool和str转换
  25. python——循环(for循环、while循环)及练习
  26. python变量和常量命名、注释规范
  27. python自定义异常捕获异常处理异常
  28. python 类型转换与数值操作
  29. python 元组(tuple)和列表(list)区别
  30. 解决python tkinter 与 sleep 延迟问题
  31. python字符串截取操作
  32. Python bool and STR conversion
  33. Python -- loop (for loop, while loop) and Practice
  34. Specification for naming and annotating variables and constants in Python
  35. Python custom exception capture exception handling exception
  36. Python type conversion and numerical operation
  37. The difference between tuple and list in Python
  38. Solve the delay problem of Python Tkinter and sleep
  39. Python string interception operation
  40. Python 100天速成中文教程,GitHub标星7700
  41. Python 100 day quick Chinese course, GitHub standard star 7700
  42. 以我的親身經歷,聊聊學python的流程,同時推薦學python的書
  43. With my own experience, I'd like to talk about the process of learning Python and recommend books for learning python
  44. python爬虫获取起点中文网人气排行Top100(快速入门,新手必备!)
  45. Python crawler to get the starting point of Chinese network popularity ranking Top100 (quick start, novice necessary!)
  46. 【Python常用包】itertools
  47. Itertools
  48. (国内首发)最新python初学者上手练习
  49. (国内首发)最新python初学者上手练习
  50. (first in China) the latest practice for beginners of Python
  51. (first in China) the latest practice for beginners of Python
  52. (数据科学学习手札104)Python+Dash快速web应用开发——回调交互篇(上)
  53. (data science learning notes 104) Python + dash rapid web application development -- callback interaction (Part 1)
  54. (数据科学学习手札104)Python+Dash快速web应用开发——回调交互篇(上)
  55. (data science learning notes 104) Python + dash rapid web application development -- callback interaction (Part 1)
  56. (資料科學學習手札104)Python+Dash快速web應用開發——回撥互動篇(上)
  57. (materials science learning notes 104) Python + dash rapid web application development -- callback interaction (Part 1)
  58. Python OpenCV 图片高斯模糊
  59. Python OpenCV image Gaussian blur
  60. Stargan V2: converse image synthesis for multiple domains reading notes and Python code analysis