mirror of
https://github.com/KUlishevgeniy/c22712.git
synced 2026-09-24 08:00:22 +00:00
This commit is contained in:
@@ -1,10 +1,23 @@
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import render
|
||||
import psycopg2
|
||||
def execute_request(request):
|
||||
connection = psycopg2.connect(host='localhost', dbname='dbdata',
|
||||
user='postgres', password='Q1w2e3r4')
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(request)
|
||||
result = cursor.fetchall()
|
||||
cursor.close()
|
||||
connection.close()
|
||||
return result
|
||||
|
||||
def index(request):
|
||||
|
||||
context = {
|
||||
"text": "test",
|
||||
"list": [0, 1, 2, 3, "frogg"]
|
||||
"data": execute_request("select name, link from parsing")[:10]
|
||||
}
|
||||
for i in range(len(context["data"])):
|
||||
context["data"][i] = list(context["data"][i])
|
||||
context["data"][i][1] = f"polls/img/{i}.jpg"
|
||||
|
||||
return HttpResponse(render(request, "polls/index.html", context))
|
||||
|
||||
Reference in New Issue
Block a user