`
vawe666
  • 浏览: 40394 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Django 一个简单mysql应用 -select

阅读更多

#修改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 数据库的存在#

0
3
分享到:
评论
3 楼 vawe666 2013-09-27  
vawe666 写道
gyfang 写道
这也能上推荐?

抬举了

以后不敢再乱用 发博选项了
2 楼 vawe666 2013-09-27  
gyfang 写道
这也能上推荐?

抬举了
1 楼 gyfang 2013-09-27  
这也能上推荐?

相关推荐

Global site tag (gtag.js) - Google Analytics