Guest User

Untitled

a guest
Jan 5th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 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 HttpResponseRedirect
  5. from models import Task
  6. import MySQLdb
  7.  
  8. DB_USER = 'root'
  9. DB_PASS = '14121988'
  10. DB_BASE = 'Decanat'
  11.  
  12. def index(request):
  13. cont = {}
  14.  
  15. if not request.user.is_authenticated():
  16. return HttpResponseRedirect('/accounts/login/')
  17.  
  18. if request.method == "POST"
  19. if 'sqlcode' in request.POST
  20. t=request.POST['sqlcode']
  21. db_conn = MySQLdb.connect(user=DB_USER, passwd=DB_PASS, db=DB_BASE)
  22. cursor = db_conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
  23. cursor.execute(t)
  24. res = cursor.fetchall()
  25. resdate = res
  26. cont['result'] = resdate
  27. return render_to_response("index.html",cont, context_instabce=RequestContext(request))
Add Comment
Please, Sign In to add comment