首页 > 数据库技术 > 详细

django python3 实例 mysql数据库

时间:2014-10-13 00:11:59      阅读:429      评论:0      收藏:0      [点我收藏+]

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数据库

原文:http://www.cnblogs.com/yanguilaixi/p/4021300.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!