Django網站管理、後台、模型(Admin)

來源:互聯網
上載者:User

標籤:

1. 啟動wampserver

2. 建立一個名為mysite的項目
django-admin.py startproject mysite

3. 建立一個叫做blog的app
cd mysite
python manage.py startapp blog

4. 修改blog檔案夾腫的models.py

# coding:utf-8from __future__ import unicode_literalsfrom django.db import modelsfrom django.utils.encoding import python_2_unicode_compatible@python_2_unicode_compatibleclass Article(models.Model):    title = models.CharField(u‘標題‘, max_length=256)    content = models.TextField(u‘內容‘)        pub_date = models.DateTimeField(u‘發布時間‘, auto_now_add=True, editable=True)    update_time = models.DateTimeField(u‘更新時間‘, auto_now=True, null=True)        def __str__(self):        return self.title

 

把blog加入到settings.py中的INSTALLED_APPS

INSTALLED_APPS = (    ‘django.contrib.admin‘,        ‘django.contrib.auth‘,        ‘django.contrib.contenttypes‘,        ‘django.contrib.sessions‘,        ‘django.contrib.messages‘,        ‘django.contrib.staticfiles‘,        ‘blog‘,)

 

同步所有的資料表
python manage.py makemigrations
python manage.py migrate

建立管理員
python manage.py createsuperuser

Username: asina
Email address: [email protected]
Password: liuqiuchen123456

修改admin.py

from django.contrib import adminfrom .models import Articleadmin.site.register(Article)

 

// 開啟程式開發伺服器
python manage.py runserver

訪問http://localhost:8000/admin/ 輸入設定的帳號和密碼

 


查看github上源碼

 

Django網站管理、後台、模型(Admin)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.