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 ...
随机推荐
- 无锁HashMap的原理与实现
转载自: http://coolshell.cn/articles/9703.html 在<疫苗:Java HashMap的死循环>中,我们看到,java.util.HashMap并不能直 ...
- bat把npm换成淘宝源
@echo off echo 开始.. npm config set registry http://registry.npm.taobao.org/ && npm install 注 ...
- [控件] LiveChangedImageView
LiveChangedImageView 效果 说明 切换图片的时候自动根据图片的尺寸进行渐变式切换,效果很不错,使用非常容易. 源码 https://github.com/YouXianMing/U ...
- 剑指offer 10矩形覆盖
我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形.请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法 java版本: public class Solution { publ ...
- linux面试总结
一.填空题:1. 在Linux系统中,以 文件 方式访问设备 .2. Linux内核引导时,从文件 /etc/fstab 中读取要加载的文件系统.3. Linux文件系统中每个文件用 i节点 来标识. ...
- Java 的字符串,String、StringBuffer、StringBuilder 有什么区别?
String 是 Java 语言非常基础和重要的类,提供了构造和管理字符串的各种基本逻辑.它是典型的 Immutable 类,被声明成为 final class,所有属性也都是 final 的.也由于 ...
- Mina使用总结(三)MinaClient
简单的Mina客户端代码MinaSimpleClient.java: package com.bypay.mina.client; import java.net.InetSocketAddress; ...
- 【错误记录】uwsgi 启动 flask 出错
在测试环境使用uwsgi启动flask未成功 正常报错信息: *** Starting uWSGI 2.0.13.1 (64bit) on [Fri Sep 23 09:27:47 2016] *** ...
- window7远程桌面到server不能复制粘贴解决的方法
用远程桌面登陆server不能在本机和远程server之间粘贴文本了,即不能从本机复制文本粘贴到server,也不能从server复制文本粘贴到本机. 下面是解决方法之中的一个,试了几次都非常管用户: ...
- SDWC补题计划
2018的寒假去了SD的冬令营,因为一班二班难度悬殊,对我很不友好,几乎什么也没学会,但是我把两个班的课件都存了下来,现在慢慢把两个班的例题以及课后题都补一补(毕竟冬令营的钱不能白花). 这些题目横跨 ...