views.py
1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from django.views.generic.base import TemplateView
from django.views.generic import FormView
from django.views.generic import View
from myapp.forms import testform
from django.db import connection
from django.shortcuts import render
class MypageView(TemplateView):
template_name = 'mypage.html'
form_class = testform
def get(self, request, *args, **kwargs):
context = {}
context['form'] = testform
query = 'SELECT * FROM vuln.vulnInfo'
param_list = []
with connection.cursor() as cursor:
cursor.execute(query, param_list)
columns = [column[0] for column in cursor.description]
object_list = []
for row in cursor.fetchall():
object_list.append(dict(zip(columns, row)))
context = {}
red = 3
blue = 4
green = 5
context['red'] = red
context['blue'] = blue
context['green'] = green
context['object_list'] = object_list
return render(self.request, self.template_name, context)
def post(self, request, *args, **kwargs):
text = self.request.POST['text']
context = {}
context['form'] = testform
print(text)
return render(self.request, self.template_name, context)
class ServerList(View):
template_name = 'test.html'
def get(self, request, *args, **kwargs):
query = 'SELECT * FROM vuln.vulnInfo'
param_list = []
with connection.cursor() as cursor:
cursor.execute(query, param_list)
columns = [column[0] for column in cursor.description]
for row in cursor.fetchall():
object_list.append(dict(zip(columns, row)))
context = {}
object_list = []
context['object_list'] = object_list
return render(self.request, self.template_name, context)
class TableView(TemplateView):
template_name = 'myapp_table.html'