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 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后台管理模块)的更多相关文章
- Linux下开发python django程序(设置admin后台管理上传文件和前台上传文件保存数据库)
1.项目创建相关工作参考前面 2.在models.py文件中定义数据库结构 import django.db import modelsclass RegisterUser(models.Model) ...
- Linux下开发python django程序(模板设置和载入数据)
1.添加templates文件夹 2.修改settings.py文件 import os #引用 os模块 BASE_DIR = os.path.dirname(os.path.dirname(os. ...
- Linux下开发python django程序
一.安装django 1.#进入包文件夹下执行解压 tar zxvf Django-1.3.7.tar.gz 2#进入解压的文件夹执行安装 python setup.py install 3#安装成功 ...
- Linux下开发python django程序(django数据库多对多关系)
1.多对多关系数据访问 models.py设置 from django.db import models # Create your models here. sex_choices=( ('f',' ...
- Linux下开发python django程序(Session读写)
1.登陆设置session信息 def loginsession(req): if req.method == 'POST': loginform = LoginForm(req.POST) if l ...
- Linux下开发python django程序(Cookie读写)
1.设置cookie信息(登陆成功后设置登陆用户名,有效期1小时) def login(req): if req.method == 'POST': loginform = LoginForm(req ...
- Linux下开发python django程序(Form表单对象创建和使用)
1.在setting.py文件中修改节点,注释掉其中一行 MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'dj ...
- Django Admin后台管理模块的使用
Admin后台管理模块的使用 Django的管理员模块是Django的标准库django.contrib的一部分.这个包还包括其它一些实用的模块: django.contrib.auth django ...
- 在linux下搭建python+django环境
下载python3,进行编译安装,运行django程序 在 /opt目录中安装 cd /opt 1.解决python编译安装所需的软件依赖 yum install gcc patch libffi-d ...
随机推荐
- Oracle EBS AR 更新客户配置文件
DECLARE l_rec_profile_t hz_customer_profile_v2pub.customer_profile_rec_type; l_rec_profile hz_custom ...
- Linux 系统安装[Ubuntu]
1.1.1. 安装Ubuntu 下载链接[Ubuntu16.04.1-64bit-Desktop版]: http://old-releases.ubuntu.com/releases/16.04.1/ ...
- 第一次项目冲刺(Alpha版本)2017/11/14
一.站立式会议 在宿舍进行了第一次会议 会议内容: 1.做了简单的分工 2.提出个人对任务是否有困难 3.规定完成时间在第三天之前 4.商量初步的代码规范 二.分工 三.任务分解图 四.燃尽图 五.数 ...
- linux块设备缓存bcache
1 Bcache介绍Bcache是一种缓存技术,它是根据SSD的特性设计的,由于SSD的随机读写速度要比普通硬盘的随机读写快N多倍,但是一般SSD的容量小且贵,当然土豪除外,所以我们可以综合SSD的读 ...
- 1260. [CQOI2007]涂色【区间DP】
Description 假设你有一条长度为5的木版,初始时没有涂过任何颜色.你希望把它的5个单位长度分别涂上红.绿.蓝.绿.红色,用一个长度为5的字符串表示这个目标:RGBGR. 每次你可以把一段连续 ...
- 【openjudge】【前缀和】P6731啤酒厂选址
[描述] 海上有一个岛,在环海边上建有一条环岛高速公路,沿着公路有n(5 < n < 10000)个居民点,假设每个居民点有一个编号,从0开始,按顺时针依次从小到大(即,0,1,…,n-1 ...
- Dictionary<string, object>
Dictionary<string, object> dcic = JsonHelper.DataRowFromJSON(resultdepth); foreach (var depthk ...
- Java常用的快捷键
// // (1)Ctrl+Space // 说明:内容助理.提供对方法,变量,参数,javadoc等得提示, // 应运在多种场合,总之需要提示的时候可先按此快捷键. // 注:避免输入法的切换设置 ...
- Elasticsearch + logstash + kibana 配置
Elasticsearch 配置 Elasticsearch不仅仅是Lucene和全文搜索,我们还能这样去描述它: 分布式的实时文件存储,每个字段都被索引并可被搜索 分布式的实时分析搜索引擎 可以扩展 ...
- 第二部分 OpenStack安装与配置
第二部分 OpenStack安装与配置 一.引言 本章内容讲解如何在3台物理机上搭建最小化云平台,这3台机器分为称为Server1.Server2和Client1,之后的各章也是如此.Server ...