1. New projects and projects under the app
Django-admin Startproject csvt03
Django-admin Startapp App1
2. Modify the settings.py file
Set the default installation app
Installed_apps = ( 'Django.contrib.auth', 'Django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'Django.contrib.staticfiles', 'App1', #uncomment the next line to enable the admin: 'Django.contrib.admin', #uncomment the next line to enable admin documentation: #' Django.contrib.admindocs ',)
Set the database to Sqlite3
DATABASES = { 'default': { 'ENGINE':'Django.db.backends.sqlite3',#Add ' postgresql_psycopg2 ', ' PostgreSQL ', ' MySQL ', ' sqlite3 ' or ' Oracle '. 'NAME':'csvt03.db',#Or Path to database file if using Sqlite3. 'USER':"',#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. }}
3. Create a new database table mapping in the models.py file
sex_choices=(('F','Famale'),('m','male'))classUser (models. Model): Name= Models. Charfield (max_length=30) Sex=models. Charfield (max_length=1,choices=sex_choices)def __unicode__(self):returnSelf.name
4. Edit the urls.py file
fromDjango.conf.urls.defaultsImportpatterns, include, url#uncomment the next lines to enable the admin: fromDjango.contribImportadminadmin.autodiscover () urlpatterns= Patterns ("', #Examples: #URL (r ' ^$ ', ' csvt03.views.home ', name= ' home '), #URL (r ' ^csvt03/', include (' Csvt03.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. Generate Data files
Python manage.py syncdb
Creating Tables ... Creating table auth_permissioncreating table auth_group_permissionscreating table auth_groupcreating table Auth_user_ user_permissionscreating table auth_user_groupscreating table auth_usercreating table auth_messagecreating table django_content_typecreating table django_sessioncreating table django_sitecreating table App1_useryou just installed The Django'S auth system, which meansyou don't have anysuperusers defined. Would to create one now? (Yes/No): Noinstalling custom SQL ... Installing indexes ... No fixtures found.
6. View the Sqlite3 database file after the build
Sqlite3 csvt03.db
Development of Python Django program under Linux (Set admin Manager module)