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 ...
随机推荐
- jenkins集成caliper"
1.jenkins安装caliper-ci插件(Caliper CI Plugin) 2.编写microbench 最简便的办法就是作为单元测试来跑(这样就不用在jenkins里配置跑microben ...
- Jmeter入门--工具组成和线程组
1.Jmeter工具组成部分: 资源生成器:用于生成测试过程中服务器,负载机的资源代码.(LoadRunner中的VuGen) 用户运行器:通常是一个脚本运行引擎,根据脚本要求模拟指定的用户行为.(L ...
- python下载指定的版本包
首先我们很多时候在执行pip的时候是不行的 有时候很难成功,这个时候我们就要想其他的版本了 一.是不是这个包需要指定版本, 比如python2的和mysql链接的是,而python3则是mysqlc ...
- DES加密(支持ARC与MRC)
DES加密(支持ARC与MRC) 源文件: YXCrypto.h 与 YXCrypto.m // // YXCrypto.h // 用秘钥给字符串加密或者解密 // // Created by You ...
- 使用YXHUD
使用YXHUD 这是本人自己设计的一个类,但功能很不完善,先看看效果: 源码: YXHUD.h 与 YXHUD.m // // YXHUD.h // UILabel // // Created by ...
- Java 的字符串,String、StringBuffer、StringBuilder 有什么区别?
String 是 Java 语言非常基础和重要的类,提供了构造和管理字符串的各种基本逻辑.它是典型的 Immutable 类,被声明成为 final class,所有属性也都是 final 的.也由于 ...
- docker学习笔记:简单构建Dockerfile【Docker for Windows】
参考与入门推荐:https://www.cnblogs.com/ECJTUACM-873284962/p/9789130.html#autoid-0-0-9 最近学习docker,写一个简单构建Doc ...
- 【cs231n】图像分类-Linear Classification线性分类
[学习自CS231n课程] 转载请注明出处:http://www.cnblogs.com/GraceSkyer/p/8824876.html 之前介绍了图像分类问题.图像分类的任务,就是从已有的固定分 ...
- SQL语句.md
数据库操作 create mysql> create database study_2; Query OK, 1 row affected (0.00 sec) mysql> show c ...
- OpenCV2马拉松第2圈——读写图片
收入囊中 用imread读取图片 用nameWindow和imshow展示图片 cvtColor彩色图像灰度化 imwrite写图像 Luv色彩空间转换 初识API 图像读取接口 image = im ...