![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python
文章平均质量分 79
紫蓝清秋
这个作者很懒,什么都没留下…
展开
-
Django3.0,Vue前后端分离以及访问静态资源的问题
首先在django项目根目录下运行 vue create myblog 创建一个vue项目myblog第二步将编写完成后的vue项目打包npm run build 会在myblog下创建一个dist文件夹,vue文件就在里面,(是需要安装好vue 和 vue cli的)vue cli 3.0+打包后,dist目录下没有static目录,而Django那边的静态资源配置只认static,所以打包之需要新建一个vue.config.js文件 ,在里面加上一段代码将静态文件放入static文件夹中原创 2020-10-22 16:17:07 · 2545 阅读 · 0 评论 -
Django 返回前端 json 对象数据
django返回json数据需要导入返回json格式的数据from django.http.response import JsonResponse需要序列化,因为jsonresponse不能返回非序列化的queryset,序列化为json字符串from django.core import serializers转为json对象import jsonfrom django.http.response import JsonResponsefrom djang原创 2020-10-22 11:39:17 · 1825 阅读 · 0 评论 -
使用Python将csv文件批量写入到MySQL数据库
因为需要,插入一些数据到数据库,就写了一个简单的批量插入这里使用的是mysqldb框架安装的话使用:pip install MySQLdb## 数据库批量添加import MySQLdb as mdbfrom datetime import datetimeimport time con = Nonefname = './loc.txt'# 打开文件遍历每一行并分割成一个数组依次存入s当中with open(fname, 'r+', encoding='utf-8')原创 2020-06-30 10:16:29 · 1568 阅读 · 0 评论 -
使用Scrapy爬取数据并保存为json、csv文件及乱码解决
安装scrapypip install scrapy创建porjectscrapy startporject tutorial执行成功后在目录下生产tutorial文件夹,结构目录如下:3. 在items.py中定义自己要抓取的数据:#定义爬取对象属性class ListItem(scrapy.Item): name = scrapy.Field() url = scrapy.Field() order = scrapy.Field() score.原创 2020-06-29 17:22:56 · 4315 阅读 · 4 评论 -
python io open()写入中文乱码问题解决
之前出现乱码代码:with open("test.txt", "wt") as out_file out_file.write("该文本写入到文件中")with open("test.txt", "rt") as in_file: text = in_file.read()print(text) #输出为: ���ı�д�뵽�ļ���解决写入中文乱码问题,在open()中添加encoding = " utf-8 "with open("test.txt", "wt", .原创 2020-06-29 15:27:02 · 3204 阅读 · 0 评论