# DjangoShop **Repository Path**: assene/DjangoShop ## Basic Information - **Project Name**: DjangoShop - **Description**: DjangoShop 是一个django为后台 并以rest api为规范的前后端分离项目 - **Primary Language**: Python - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 0 - **Created**: 2018-07-10 - **Last Updated**: 2021-01-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # DjangoShop #### 项目介绍 超市电商的django2 后端项目 ### 环境概览 1. djangoweb框架及 restframework 2. 数据库mysql 后台管理系统xadmin 3. markdown编辑器ckeditor ## 项目搭建指南 - 创建python 虚拟环境:virtualenv -p D:\python\python.exe VueShop - 切换到虚拟环境:Scripts\activate ### 安装django和djangorestframework 1. pip install djangorestframework 2. pip install Django 3. pip install markdown 4. pip install django-filter 5. 安装 pip install mysqlclient 6. 安装图片处理pip install pillow 7. pip install coreapi 及pip install django-guardian 8. pip install djangorestframework-jwt ### 生成数据表 1. makemigrations 2. migrate 3. 一般datetime的长度为0, - 关于 django 的datetime长度为6 问题:把django/db/backends/mysql/base.py里的 原DateTimeField='datetime(6)' 改成 DateTimeField='datetime(0)' ### 后台管理系统 xadmin https://github.com/sshwsfc/xadmin - django2版本,请选择django2分支。项目依赖在requirements.txt里,我的做法是下载这个版本到本地,用pip install 安装它 (xadmin依赖)pip install 安装以下包: - django>=2 - django-crispy-forms>=1.6.0 - django-import-export>=0.5.1 - django-reversion>=2.0.0 - django-formtools==2.1 - future==0.15.2 - httplib2==0.9.2 - six==1.10.0 ### excel导入导出依赖: - xlwt - xlsxwriter ### django redis 缓存 pip install django-redis ### django 的全自动文档生成 include_docs_urls, url.py 里加上path(r'docs/',include_docs_urls(title="生鲜超市")), ### 常见错误和解决方法 1. mysqlclient 等依赖安装失败:进入网址https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient, 选择对应的项目和版本下载whl文件 用命令pip install 文件 安装 2. django2 对于SQL ForeignKey约束中,必须声明on_delete,而django1.X版本并不需要 3. 关于django的datetime类型原来为6,建议修改为 DateTimeField='datetime(0)' 关于DjangoUeditor的错误不再修复,加入另一插件:pip install django-ckeditor - settings配置,在其中加入这两个 ``` python INSTALLED_APPS = [ 'ckeditor', 'ckeditor_uploader'] ``` - 确保media路径配置好,ckeditor的上传路径在media下 ``` python MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media_cdn') CKEDITOR_UPLOAD_PATH = 'upload/' ``` - url: ``` python url(r'ckeditor/', include('ckeditor_uploader.urls')) ``` - models: ``` python from ckeditor_uploader.fields import RichTextUploadingField class Post(models.Model): content = RichTextUploadingField(null=True, blank=True) ``` 4. pycharm 运行django 程序发生过错误 - pycharm Requested setting DEBUG, but settings are not configured - 在Run 里的EditConfigures,修改Environment variables添加一项:DJANGO_SETTINGS_MODULE 值是项目名称.settings 5. python代码规范 ### inconsistent use of tabs and spaces in indentation 这个报错就是混用了tab和4个空格造成的,检查代码,要不全部用tab,要不全部用4个空格,或者用idle编辑器校正