2019-nCov epidemic real-time data visualization-30 minutes python fast version
When the epidemic is coming, it is better to learn how to use python to develop and deploy a real-time tracking visualization page of the epidemic when staying at home. Page preview
This article will introduce how to use python to develop a website, "Because it takes 30 minutes to quickly build a deployment version, so the configuration process description of all the configuration item files in Django will be omitted." The detailed configuration process will be under the column "Full version of Django development website" In the description. This is also the step I recommend for general learning python: "By quickly getting started with a project, first learn the routines and run the program, and then look back at the relevant development documents . "
Because I have gone through the process of developing and deploying websites with Django many times, I basically wrote this document as simple as possible from the perspective of God. All the software in it is introduced in my historical articles. Of course, for Xiaobai, there will definitely be places that I don t understand, or which step reported an exception that I didn t write down. If you have any questions, please raise them so let s start.
- [ "Must" ] A server with anaconda and mysql configured. If you don t have a server yet, you can read the column to buy and configure your own cloud server
- A computer with mysql configured. You can click on how to configure mysql under centos under the column
- Basic programming knowledge
- Software: Navicat, filezilla (introduced in the column)
- Python related: requests, pyecharts, Django
The requirements of this development are very clear, in short, it is three steps
- Crawl data
- data visualization
- Deploy the visualized results to the server
Then the first two steps above can read my previous articles, which have explained in detail how to obtain data from the Internet and use pyecharts for visualization. Then I assume that you have already written a visualization program. At the end of visualization using pyecharts, use
.render('map1.html')# html map1.html
Generate and save the map, pie chart, etc. we need to display in html format so that we can embed it in the web page later. Then leave it to "Django" .
Install Django and the required modules
First execute the following code to install Django and database-related modules
# Django pip install django # pip install pymysql pip install mysqlclient
Because we are using mysql, there will be an error in the following Django synchronization database. Because it is a fast deployment, we directly modify the relevant files in advance to solve the error. (If you are interested, you can watch the full version step by step after the deployment is completed, and then solve it after the synchronization database reports an error.
Use filezilla to connect to your remote server, if you configured anaconda according to my article, open the following path
Find the following in base.py comment
if version < (1, 3, 13): raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
Then open operations.py in this folder , modify about 146 lines, and change decode to encode
query = query.decode(errors='replace')
After completing the above two steps, overwrite the modified file and transfer it to the original folder.
"Of course the above modification steps can be lazy to save time and download the modified ones directly."
Now ssh connect to your server, after installing Django, execute the following code:
django-admin startproject djtest
It means that a Django project named djtest is created. If nothing else, refreshing the directory in filezilla will create an extra folder named djtest, and then execute it to
cd djtestenter the folder, and
python manage.py startapp webthen refresh the folder after execution , there will be more A web folder. Under normal circumstances, you need to configure the settings.py and other related configuration files in the folder (including database configuration, form settings, page registration, etc.). The process is relatively complicated, so you don't need to configure it for the time being.
"Directly download the configured folder" directly upload the entire file to the server and overwrite the djtest folder.
But it s not completely lazy, you still need to complete a few steps,
- After the overwriting is complete, you need to download the settings.py file inside, and modify the database password inside to the password you set in the configuration database before. Then upload and overwrite the original.
- Replace the map1.html and mp2.html in the static folder with the html file you just generated for the area you are concerned about and upload it.
Then use Navicat to connect to your own remote database, follow the steps below to create a database named djtest
python manage.py migrate
So far, 99% has been completed, only the last step is to execute
nohup python manage.py runserver 0.0.0.0:8000 &
Go to Alibaba Cloud and add port 8000 to the security group according to the method mentioned in the previous article.
At this point, just find a browser and enter your ip:8000, you can successfully see the website you deployed, then how to further personalize the website (add login module, add modified chart, add modified text) or I want to achieve other functions, which will be explained in the full version of the development tutorial. At least here, you have developed your own epidemic data tracking website.
Source code attention to the public account: early python