django读取excel表格并引用自定义函数 , 然后插入mysql数据库库
view.py
# -*- coding: utf-8 -*-
# 上一句话是要识别中文
from __future__ import unicode_literals
from django.shortcuts import render
from cmdb import models
from django.shortcuts import HttpResponse
from django.http import JsonResponse
import json
from django.core import serializers
# Create your views here.
from django.views.decorators.cache import cache_page
# 引入自定义模块
from cmdb.myfunction import to_mysql
# 导入excel 需要的包 需要用pip安装
# pip install xlrd
import xlrd
import uuid
import random
@cache_page(60 * 15) # 秒数,这里指缓存 15 分钟,不直接写900是为了提高可读性 这要提高加载速度
# 读取excel表格
def excel_import(request):
file_excel = 'C:/Users/Administrator/Desktop/data.xls'
col_name_index = 0
by_name = u'Sheet1'
data = xlrd.open_workbook(file_excel)
table = data.sheet_by_name(by_name)
n_rows = table.