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 Django's auth system, which means you don't 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

7.在app1中添加admin.py文件,并在文件中添加管理员模块数据库映射

from django.contrib import admin
from app1.models import User admin.site.register(User)

8运行开发服务器:

python manage.py runserver

访问127.0.0.1:8000/admin

Linux下开发python django程序(设置admin后台管理模块)的更多相关文章

  1. Linux下开发python django程序(设置admin后台管理上传文件和前台上传文件保存数据库)

    1.项目创建相关工作参考前面 2.在models.py文件中定义数据库结构 import django.db import modelsclass RegisterUser(models.Model) ...

  2. Linux下开发python django程序(模板设置和载入数据)

    1.添加templates文件夹 2.修改settings.py文件 import os #引用 os模块 BASE_DIR = os.path.dirname(os.path.dirname(os. ...

  3. Linux下开发python django程序

    一.安装django 1.#进入包文件夹下执行解压 tar zxvf Django-1.3.7.tar.gz 2#进入解压的文件夹执行安装 python setup.py install 3#安装成功 ...

  4. Linux下开发python django程序(django数据库多对多关系)

    1.多对多关系数据访问 models.py设置 from django.db import models # Create your models here. sex_choices=( ('f',' ...

  5. Linux下开发python django程序(Session读写)

    1.登陆设置session信息 def loginsession(req): if req.method == 'POST': loginform = LoginForm(req.POST) if l ...

  6. Linux下开发python django程序(Cookie读写)

    1.设置cookie信息(登陆成功后设置登陆用户名,有效期1小时) def login(req): if req.method == 'POST': loginform = LoginForm(req ...

  7. Linux下开发python django程序(Form表单对象创建和使用)

    1.在setting.py文件中修改节点,注释掉其中一行 MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'dj ...

  8. Django Admin后台管理模块的使用

    Admin后台管理模块的使用 Django的管理员模块是Django的标准库django.contrib的一部分.这个包还包括其它一些实用的模块: django.contrib.auth django ...

  9. 在linux下搭建python+django环境

    下载python3,进行编译安装,运行django程序 在 /opt目录中安装 cd /opt 1.解决python编译安装所需的软件依赖 yum install gcc patch libffi-d ...

随机推荐

  1. SQLSERVER中KeyHashValue的作用(上)

    SQLSERVER中KeyHashValue的作用(上) SQLSERVER中KeyHashValue的作用(下) 原文的标题是:SQLSERVER在索引下如何找到哈希值的随想 现在知道KeyHash ...

  2. Docker 命令总结

    1 启动镜像 docker run -i -t centos /bin/bash

  3. 绕过CDN查找网站真实IP方法收集

    方法1很简单,使用各种多地 ping 的服务,查看对应 IP 地址是否唯一,如果不唯一多半是使用了CDN, 多地 Ping 网站有: http://ping.chinaz.com/ http://pi ...

  4. SDN上机第二次作业

    SDN第二次上机作业 1.安装floodlight 参考链接:http://www.sdnlab.com/19189.html 2.生成拓扑并连接控制器floodlight,利用控制器floodlig ...

  5. 在Ubuntu Desktop中安装软件

    1. 安装好虚拟机后,可以先打开firefox,看是否可以访问外部的网页. 2. 如果在公司内网,可能访问不起,需要添加代理,确保可以访问外部的网页. 3. 更新软件源 sudo apt update ...

  6. 【转】【iOS开发】打开另一个APP(URL Scheme与openURL)

    目标 平常我们做iOS开发,会经常遇到打开其他的APP的功能.本篇文章讲的就是打开别人的APP的一些知识.我们的目标是: 打开别人的APP 让别人打开我们的APP iOS9的适配问题 使用URL Sc ...

  7. android scheme打开天猫,淘宝

    直接上代码 Intent intent = new Intent(); intent.setAction("android.intent.action.VIEW"); /* Str ...

  8. php中static静态变量的使用方法详解

    php中的变量作用范围的另一个重要特性就是静态变量(static 变量).静态变量仅在局部函数域中存在且只被初始化一次,当程序执行离开此作用域时,其值不会消失,会使用上次执行的结果.     看看下面 ...

  9. 使用redis4.0.1和redis-cluster搭建集群并编写重启shell脚本

    1.删除机器上原有的redis2.8 关闭redis-server killall -9 redis-server 查找redis文件所在目录 which redis 删除相关文件 rm -rf re ...

  10. 随手练——HDU 5015 矩阵快速幂

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5015 看到这个限时,我就知道这题不简单~~矩阵快速幂,找递推关系 我们假设第一列为: 23 a1 a2 ...