django admin扩展 相关备忘录

本文介绍了Django项目的配置过程,包括settings.py中关键模块的安装与设置、urls.py中的路径映射配置、创建及注册app的具体步骤。此外还涉及了模型定义、数据库同步等实用操作。
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,如需转载请自行联系原作者

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值