blog项目步骤

2019-06-26  本文已影响0人  鸡杂面

1.在我的work文件下创建blog文件,进入该文件执行django-admin startproject blog .


图片.png
图片.png
  1. 安装mysqlclient,
pip install mysqlclient

会报错,是因为系统问题,
到这个网站下载对应版本的资源
https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient

  1. 修改settings.py里的DATABASES


    图片.png
  2. 创建用户应用

from django.db import models

# Create your models here.
class User(models.Model):
    class Meta:
        db_table = 'user'

    id = models.AutoField(primary_key = True)
    name = models.CharField(max_length = 48, null = False)
    email = models.CharField(max_length = 64, null = False, unique = True)
    password = models.CharField(max_length = 128, null = False)

    def _repr_(self):
        return "".format(self.id,self.name)
    
    _str_ = _repr_
  1. python manage.py makemigrations


    图片.png
  2. 迁移(迁移的应用必须在settings.py的INSTALLED_APPS中注册)
    python manage.py migrate


    图片.png
    在mysql生成表.png
  3. 修改时区
    在settings.py里

LANGUAGE_CODE = 'zh-Hans'

TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True

USE_L10N = True

USE_TZ = True
上一篇下一篇

猜你喜欢

热点阅读