复制category_data、goods_data文件
编写导入文件import_category_data、import_goods_data
在项目settings里,STATIC_URL = '/static/'后添加下面配置
MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
在urls里添加配置
from MxShop.settings import MEDIA_ROOT from django.views.static import serve #静态文件 url(r'^media/(?P<path>.*)$', serve, {"document_root": MEDIA_ROOT}),
遇到的问题:
1、执行import_category_data导入文件时,报错:
DateTimeField GoodsCategory.add_time received a naive datetime (2021-11-19 03:10:20.851469) while time zone support is active. warnings.warn("DateTimeField %s received a naive datetime (%s)"
#设置时区 LANGUAGE_CODE = 'zh-hans' #中文支持,django1.8以后支持;1.8以前是zh-cn TIME_ZONE = 'Asia/Shanghai' USE_I18N = True USE_L10N = True USE_TZ = False #默认是Ture,时间是utc时间,由于我们要用本地时间,所用手动修改为false!!!!
2、执行倒入文件import_goods_data时,报错:
TypeError: render() got an unexpected keyword argument 'renderer'
参考:https://www.cnblogs.com/python-boy/p/11290606.html