#修改setting.py#
DATABASES = {
'default': {
'ENGINE': 'mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME':'ilordb', # Or path to database file if using sqlite3.
'USER':'root', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '3306', # Set to empty string for default. Not used with sqlite3.
}
}
#在your prj 项目目录中新建一个 xxx.py#
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.db import connection, transaction
def Getab_type(request):
cursor=connection.cursor()
sql="SELECT F_Id,F_Name FROM tab_type WHERE F_Id=1"
cursor.execute(sql)
tab_types=cursor.fetchone()
cursor.close()
return render_to_response('testmysql\show.html',{'typeId':tab_types[0],'typeName':tab_types[1]})
#使用 templete 略 #
#添加 urls.py#
(r'^show/$', Getab_type),
#要保证 mysql 数据库的存在#