数据导入
前言
代码已上传至github:https://github.com/kalipoison/fresh-market
此项目仅学习用途
流程
将good,brands文件夹数据导入media文件夹。
修改settings.py
settings.py
MEDIA_URL = "/media/"
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
修改Mxshop下的url.py
url.py
from django.conf.urls import url
# from django.contrib import admin
import xadmin
from Mxshop.settings import MEDIA_ROOT
from django.views.static import serve
urlpatterns = [
url(r'^xadmin/', xadmin.site.urls),
url(r'^media/(?P<path>.*)$', serve, {
"document_root": MEDIA_ROOT}),
]
在db_tools文件夹下新建文件夹data,和 import_category_data.py,import_goods_data.py。
import_category_data.py
#!/usr/bin/env python
# encoding: utf-8
#独立使用django的model
import sys
import os
pwd