|
1.创建project
django-admin.py startproject test01
2.创建app
django-admin.py startapp blog
3.修改settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'yanchao01', # Or path to database file if using sqlite3.
'USER': 'root', # Not used with sqlite3.
'PASSWORD': '***', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog', 添加app
# Uncomment the next line to enable the admin:
'django.contrib.admin', 开启admin
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
4.修改urls.py
from django.conf.urls.defaults import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'test01.views.home', name='home'),
# url(r'^test01/', include('test01.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
5.vim blog/models.py 创建blog_test01表 字段为name sex
from django.db import models
sex_choices=(
('f','famale'),
('m','male'),
)
class Test01(models.Model):
name = models.CharField(max_length=20)
sex = models.CharField(max_length=20,choices=sex_choices)
def __unicode__(self):
return self.name
6.vim blog/admin.py
#!/usr/bin/python
from django.contrib import admin
from blog.models import Test01
admin.site.register(Test01) 注册blog_test01到admin后台
7.python manger.py runserver
|
|