django python3 实例 mysql数据库

views.py中代码:

def show_all_user(req):
num=1
if ‘pagenum‘ in req.POST:
num=req.POST[‘pagenum‘]
tlist=User.objects.all()
p=Paginator(tlist,30)
page=p.page(num)
return render_to_response(‘show_all_user.html‘,{‘all_user‘:page.object_list,‘pagenum‘:num,‘total‘:range(1,p.num_pages+1)})

 

settings.py


import os


BASE_DIR = os.path.dirname(os.path.dirname(__file__))
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__), ‘../templates‘).replace(‘\\‘,‘/‘),
os.path.join(os.path.dirname(__file__), ‘../activitypush/templates/‘).replace(‘\\‘,‘/‘),
# os.path.join(os.path.dirname(__file__), ‘../activitypush/js/‘).replace(‘\\‘,‘/‘),
os.path.join(os.path.dirname(__file__), ‘../mysite/templates/‘).replace(‘\\‘,‘/‘),
os.path.join(os.path.dirname(__file__), ‘../upload/templates/‘).replace(‘\\‘,‘/‘),

os.path.dirname(os.path.dirname(__file__)),


os.path.join(os.path.dirname(__file__), ‘../activitypush/static/js/‘).replace(‘\\‘,‘/‘),
os.path.join(os.path.dirname(__file__), ‘../mysite/templates/‘).replace(‘\\‘,‘/‘),
)

STATIC_URL = ‘/static/‘


STATICFILES_DIRS = (
os.path.join(os.path.dirname(__file__), ‘../static/‘).replace(‘\\‘,‘/‘),
os.path.join(os.path.dirname(__file__), ‘../activitypush/static/‘).replace(‘\\‘,‘/‘),
os.path.join(os.path.dirname(__file__), ‘../mysite/static/‘).replace(‘\\‘,‘/‘),
os.path.join(os.path.dirname(__file__), ‘../clientloading/static/‘).replace(‘\\‘,‘/‘),
os.path.join(os.path.dirname(__file__), ‘../upload/static/‘).replace(‘\\‘,‘/‘),
os.path.join(os.path.dirname(__file__), ‘../myauth/static/‘).replace(‘\\‘,‘/‘),
)

STATIC_PATH = os.path.join(os.path.dirname(__file__), ‘../templates‘).replace(‘\\‘,‘/‘)

SECRET_KEY = ‘a=is^$ivb)$s5$_fq+(6leza+&2z$=(s-2-*v4i$@b#z66j*yu‘

# SECURITY WARNING: don‘t run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []

SITE_ID = 1

# Application definition

INSTALLED_APPS = (
‘django.contrib.admin‘,
‘django.contrib.auth‘,
‘django.contrib.contenttypes‘,
‘django.contrib.sessions‘,
‘django.contrib.messages‘,
‘django.contrib.staticfiles‘,

‘django.contrib.sites‘,
‘django.contrib.admindocs‘
)

MIDDLEWARE_CLASSES = (
‘django.contrib.sessions.middleware.SessionMiddleware‘,
‘django.middleware.common.CommonMiddleware‘,
‘django.middleware.csrf.CsrfViewMiddleware‘,
‘django.contrib.auth.middleware.AuthenticationMiddleware‘,
‘django.contrib.messages.middleware.MessageMiddleware‘,
‘django.middleware.clickjacking.XFrameOptionsMiddleware‘,

‘django.core.files.uploadhandler.MemoryFileUploadHandler‘,
‘django.core.files.uploadhandler.TemporaryFileUploadHandler‘,
)

ROOT_URLCONF = ‘mysite.urls‘

WSGI_APPLICATION = ‘mysite.wsgi.application‘

 

DATABASES = {
‘default‘: {
‘ENGINE‘:‘django.db.backends.mysql‘,
‘NAME‘: ‘django‘,
‘USER‘: ‘root‘,
‘PASSWORD‘: ‘root‘,
‘HOST‘: ‘localhost‘,
‘PORT‘: ‘3306‘,
}
}

 

完整代码下载地址为:http://download.csdn.net/detail/dxldehuali/8030623

小编的店铺地址,欢迎光顾:http://yunduosuper.taobao.com/

django python3 实例 mysql数据库

上一篇:PHP 认识PDO数据库抽象层


下一篇:System.Data.OracleClient 需要 Oracle 客户端软件 version 8.1.7 或更高版本