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
Data query rendering
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 .
[「 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
The requirements of this development are very clear , In short, it's three steps
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
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
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 .
Then use navicat Connect to your own remote database , Follow these steps to create one called djtest The database of
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 .