时间:2021-07-01 10:21:17 帮助过:22人阅读
pip安装mysqlclient
sudo ln -s /usr/local/mysql/bin/mysql_config /usr/local/bin/mysql_config
sudo pip install mysqlclient
配置数据库
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django',
'USER': 'root',
'PASSWORD': '123456',
'HOST': '',
'PORT': '',
}
}
设置models
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
# Create your models here.
class User(models.Model):
name = models.CharField(max_length=20)
age = models.IntegerField(max_length=11)
gender = models.CharField(max_length=1)
操作数据库
def index(request):
test = User.objects.get(id=1)
test.gender = '女'
test.save()
return HttpResponse('修改成功')
Django 操作Mysql数据库
标签:ase 数据 sql数据库 HERE test usr 安装mysql def pre