Guest User

Untitled

a guest
Jan 5th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. from django.template import RequestContext
  3. from django.shortcuts import render_to_response
  4. from django.http import HttpResponse
  5. import MySQLdb
  6.  
  7. DB_USER = 'root'
  8. DB_PASS = '14121988'
  9. DB_BASE = 'Decanat'
  10. def index(request):
  11. cont = {}
  12. self={}
  13. if request.method == "POST":
  14. if 'sqlcode' in request.POST:
  15. t=request.POST['sqlcode']
  16. self.db_conn = MySQLdb.connect(user=DB_USER, passwd=DB_PASS, db=DB_BASE)
  17. self.cursor = self.db_conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
  18. self.cursor.execute(t)
  19.  
  20. res = self.cursor.fetchall()
  21. self.send_response(200)
  22. elf.send_header('Content-type','text/html; charset=utf-8')
  23. self.end_headers()
  24. cont['result'] = res
  25.  
  26.  
  27.  
  28.  
  29.  
  30. return render_to_response("index.html",cont, context_instance=RequestContext(request))
Add Comment
Please, Sign In to add comment