zoukankan      html  css  js  c++  java
  • Django创建数据表

    Django中创建表。 用的django项目自带的sqlite数据库,创建完毕后将表注冊到jdango.admin,就能够在浏览器在管理了。 

    django项目的models.py文件里:

    from django.db import models

    # Create your models here.

    class Author(models.Model):
        name models.CharField(max_length=100)
        age models.IntegerField(default=18)

    class Article(models.Model):
        title models.CharField(max_length=200)
        content models.TextField()
        url models.URLField()
        portal models.ImageField()
        author models.ForeignKey(Author)

      

    Python manage.py makemigrations

     

    用sqlite查看是否真的创建表成功:

     

    Python manage.py createsuperuser

     

    或者

    Pycharm

    Run-->Run manage.py Task...-->Syncdb

     

     

    在浏览器查看

    admin.py中增加例如以下代码:

    from django.contrib import admin
    from blog.models import *
    # Register your models here.
    admin.site.register(Article)
    admin.site.register(Author)

    http://localhost:8000/admin

    username:adminstrator

    password:0

      

    登录成功!

     

  • 相关阅读:
    mv、umask、chattr、lsattr命令
    mkdir、whoami、touch
    man命令
    hostname、uname、dmesg、fdisk
    find命令
    etc下
    echo命令
    date 、cal、bc
    表白程序源代码,android
    设置Windows 8.1屏幕自己主动旋转代码, Auto-rotate function code
  • 原文地址:https://www.cnblogs.com/tlnshuju/p/6962480.html
Copyright © 2011-2022 走看看