cmd到 django 的manage.py 同目录下(后面不再赘述)
python manage.py runserver
特定地址和端口,可以再后面加上:127.0.0.1:8000 (127.0.0.1是本地地址,8000是默认端口)
python manage.py inspectdb
python manage.py inspectdb > [此处填写app名称]/models.py
from .models import * #导入表类
#例如
def changeuserinfo(request): #userid,username
if request.method == "POST":
info = json.loads(request.body)
userid = info['userid'] # id
username = info['username'] # 姓名
user = UserInfo.objects.get(userid= userid) # select 该userid字段的对象
user.username = username # 修改username
user.save() # 保存至数据库中
对应的models类:
class UserInfo(models.Model):
userid = models.AutoField(primary_key=True)
username = models.CharField(max_length=200, blank=True, null=True)
class Meta:
managed = False
db_table = 'user_info'