码迷,mamicode.com
首页 > 编程语言 > 详细

Linux下开发python django程序(设置admin后台管理模块)

时间:2016-09-21 10:20:08      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:

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 admin
admin.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_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table app1_user

You just installed Djangos auth system, which means you dont have any superusers defined.
Would you like to create one now? (yes/no): no
Installing custom SQL ...
Installing indexes ...
No fixtures found.

6. 查看生成后的sqlite3数据库文件

sqlite3 csvt03.db

 

Linux下开发python django程序(设置admin后台管理模块)

标签:

原文地址:http://www.cnblogs.com/whzym111/p/5891470.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!