使用Django上传和下载CSV文件

我使用Python + Django进行了与此页面类似的操作,即CSV文件下载/上传。

The following is an option for paraphrasing the phrase “違いは” (The difference is) in Chinese:

区别在于

操作系统为Arch Linux
数据库为MariaDB
库为django-bootstrap4
csv文件的字符编码为utf-8。

代码存放在GitHub上。
ekzemplaro/django_csv_upload_download

步骤

1)安装图书馆

sudo pip install django-bootstrap4

2) 准备 MariaDB

用户名:django
密码:tiger123
数据库:django_csv

MariaDB [(none)]> create user django@localhost identified by 'tiger123';
MariaDB [(none)]> select user,host from mysql.user;
MariaDB [(none)]> create database django_csv;
MariaDB [(none)]> grant all on django_csv.* to django@localhost;

3) 从GitHub复制

git clone https://github.com/ekzemplaro/django_csv_upload_download

4) 创建数据库

cd proj01
python manage.py makemigrations csvdownload
python manage.py migrate
python manage.py createsuperuser

5)启动开发服务器

python manage.py runserver

6) 使用浏览器访问 http://127.0.0.1:8000/

7) 举个例子,将下一个文件上传

102,社長
103,部長
104,課長

我在下一个版本中进行了确认。

$ python --version
Python 3.9.7
$ python -m django --version
3.1.4
bannerAds