django admin擴充套件 相關備忘錄

weixin_33763244發表於2017-11-23
porject相關
 
settings.py
 
INSTALLED_APPS = ( 
        'django.contrib.auth', 
        'django.contrib.contenttypes', 
        'django.contrib.sessions', 
        'django.contrib.sites', 
  'django.contrib.admin', 
  'mypyblog.polls', 
)
 
 
urls.py
from django.conf.urls.defaults import * 

# Uncomment the next two lines to enable the admin: 
from django.contrib import admin 
admin.autodiscover() 

urlpatterns = patterns('', 
        # Example: 
        # (r'^mypyblog/', include('mypyblog.foo.urls')), 

        # Uncomment the admin/doc line below and add 'django.contrib.admindocs'    
        # to INSTALLED_APPS to enable admin documentation: 
        # (r'^admin/doc/', include('django.contrib.admindocs.urls')), 

        # Uncomment the next line to enable the admin: 

  (r'^admin/(.*)', admin.site.root),    
)
 
 
 
app相關
 
建立app之後 新增models
# -*- coding: utf-8 -*- 
from django.db import models 

# Create your models here. 

class Topic(models.Model): 
        title = models.CharField(max_length=100) 
        content = models.CharField(max_length=50) 
        
class Admin(models.Model): 
        username = models.CharField(max_length=10) 
        password = models.CharField(max_length=16)
 
ORM模型正確性檢驗
python manage.py validate
檢視資料庫結構
python manage.py sql polls
同步資料庫
python manage.py syncdb
 
 
在app下建立一個admin.py


from django.contrib import admin 
from mypyblog.polls.models import Topic, Admin 
admin.site.register(Topic) 
admin.site.register(Admin) 
 
啟動測試伺服器
python manage.py runserver
 


本文轉自阿汐 51CTO部落格,原文連結:http://blog.51cto.com/axiii/180994,如需轉載請自行聯絡原作者

相關文章