首页 > 代码库 > Linux下开发python django程序(设置admin后台管理模块)
Linux下开发python django程序(设置admin后台管理模块)
1.新建项目和项目下APP
django-admin startproject csvt03
django-admin startapp app1
2.修改settings.py文件
设置默认安装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‘,)
设置数据库为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.在models.py文件中新建数据库表映射
sex_choices=((‘f‘,‘famale‘),(‘m‘,‘male‘))class User(models.Model): name = models.CharField(max_length=30) sex=models.CharField(max_length=1,choices=sex_choices) def __unicode__(self): return self.name
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 adminadmin.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.生成数据文件
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 Django‘s auth system, which means you don‘t have any superusers defined.Would you like to create one now? (yes/no): noInstalling custom SQL ...Installing indexes ...No fixtures found.
6. 查看生成后的sqlite3数据库文件
sqlite3 csvt03.db
Linux下开发python django程序(设置admin后台管理模块)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。