詳細(xì)閱讀(http://www.cnblogs.com/wupeiqi/articles/5246483.html)
-
數(shù)據(jù)庫(kù)添加字段類型方法步驟:
-
1
(python manage.py makemigrations)
-
2
-
3
(python manage.py migrate)
-
為自己創(chuàng)建后臺(tái)管理
(http://127.0.0.1:8000/admin/login/?next=/admin/)
- 創(chuàng)建超級(jí)用戶
(python manage.py createsuperuser)(u:root,e:123@qq.com, m:qwerasdf)
-
AutoField(primary_key=True)表示自增, 固定寫法
uid = models.AutoField(primary_key=True)
-
代碼如下:
- models.py:
from django.db import models
# Create your models here.
class UserGroup(models.Model): # models.Model注意一定要有否則不能創(chuàng)建表
# AutoField(primary_key=True)表示自增, 固定寫法
uid = models.AutoField(primary_key=True)
caption = models.CharField(max_length=32)
class UserInfo(models.Model):
# Django自動(dòng)創(chuàng)建id列,自增,主鍵
# 用戶名列,字符串類型,指定長(zhǎng)度
# 字符串.數(shù)字.時(shí)間.二進(jìn)制
username = models.CharField(max_length=32)
password = models.CharField(max_length=64)
email = models.CharField(max_length=60)
test = models.EmailField(max_length=19,null=True)
- admin.py
from django.contrib import admin
from app01 import models
# Register your models here.
admin.site.register(models.UserInfo)
- s14day19_2\urls.py:
from django.conf.urls import url,include
from django.contrib import admin
# from app01 import views as V1
# from app02 import views as V2
# from app01 import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^cmdb/', include("app01.urls")),
url(r'^monitor/', include("app02.urls")),
]
"""
urlpatterns = [
url(r'^admin/', admin.site.urls),
# url(r'^index/', views.index),
url(r'^asdfasdfasdf/(?P<nid>\d+)/(?P<uid>\d+)/', views.index, name='indexx'),
url(r'^login/', views.login),
# url(r'^home/', views.home),
# views.Home.as_view()是固定用法
url(r'^home/', views.Home.as_view()),
# url(r'^detail/', views.detail),
url(r'^detail-(\d+).html', views.detail),
# url(r'^detail-(\d+)-(\d+).html', views.detail),
# url(r'^detail-(?P<nid>\d+)-(?P<uid>\d+).html', views.detail),
]
"""