标签:database dir splay 规则 连接 post cti html 依赖包
学习资料:
1.django模型字段文档:https://docs.djangoproject.com/…
2.在SQL中ntext和text类型的的区别:http://www.uzzf.com/news/2210.html
一、搭建环境
安装virtualenvwrapper:https://www.jianshu.com/p/7ed2dfa86e90
创建虚拟环境: mkvirtualenv –-python= python.exe路径 环境名(net_book)
进入虚拟环境:workon 环境名(net_book)
安装依赖包:pip install django==2.2 –i https://pypi.douban.com/simple/
pip install pymysql # 连接MySQL数据库
pip install django-redis # 连接Redis数据库
pip install djangorestframework # RESTFual规则
pip install pillow # 图片处理包
二、编辑项目
1、创建项目:django-admin startproject 项目名(net_book) (存放项目的文件夹下)
2、创建应用:python manage.py startapp 应用名(Book) (在项目文件夹下运行)
3、设置settings:
在INSTALLED_APPS中添加’rest_framework’, ‘Book’,
LANGUAGE_CODE = ‘zh-hans’
USE_ZONM = ‘Asia/Shanghai’
USE_TZ = False
4、创建模型:Pycharm连接Mysql失败. [08001] Could not create c。。。
Ebook模型:
1 from django.db import models 2 from Books.constants import * 3 4 class Ebook(models.Model): 5 name = models.CharField(max_length=32) 6 author = models.CharField(max_length=32) 7 introduction = models.TextField() 8 type = models.IntegerField(default=UNCLASSIFIED) 9 status = models.IntegerField(default=SERIAL) 10 price = models.DecimalField(max_digits=6, decimal_places=2, default=‘0‘) 11 thumbnail = models.ImageField(upload_to=f‘media/uploads/thumbnail/%Y/%m‘) 12 bookcase_num = models.IntegerField(default=0) 13 vote_num = models.IntegerField(default=0) 14 weight = models.IntegerField(default=WEIGHT_DEFAULT) 15 class Meta(): 16 db_table = ‘book‘
Content模型:
1 class Content(models.Model): 2 suffix1 = models.TextField() 3 suffix2 = models.TextField() 4 suffix3 = models.TextField() 5 suffix4 = models.TextField() 6 suffix5 = models.TextField() 7 suffix6 = models.TextField() 8 suffix7 = models.TextField() 9 suffix8 = models.TextField() 10 suffix9 = models.TextField() 11 suffix0 = models.TextField() 12 class Meta(): 13 db_table = ‘content‘
设置settings:
1 DATABASES = { 2 ‘default‘: { 3 # ‘ENGINE‘: ‘django.db.backends.sqlite3‘, 4 # ‘NAME‘: os.path.join(BASE_DIR, ‘db.sqlite3‘), 5 ‘ENGINE‘: ‘django.db.backends.mysql‘, 6 ‘NAME‘: ‘net_book‘, 7 ‘USER‘: ‘root‘, 8 ‘PASSWORD‘: ‘your password‘, 9 ‘HOST‘: ‘127.0.0.1‘, 10 ‘POST‘: ‘3306‘, 11 } 12 }
生成迁移文件:Python manage.py makemigrations
迁移数据:pyhton manage.py migrate
5、创建序列化器:
在Books中创建serialization.py
标签:database dir splay 规则 连接 post cti html 依赖包
原文地址:https://www.cnblogs.com/yulincoco/p/11944500.html