Код в Django не работает. Форма в html не открывает вывод при нажатии на submit

Я работаю над простым проектом, в котором я хочу прочитать pdf с помощью формы в html и затем отобразить содержимое pdf на другой странице в формате словарь ключ значение. Вот код, который у меня есть на данный момент. Проблема в том, что когда я нажимаю на кнопку submit, не выполняется даже условие else и ничего не происходит.

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Pdf Reader</title>
</head>
<body>
<form enctype='multipart/form-data' action='/analyze' method='POST'>
    <div class="input-group">
        <input type="file" name="inp" class="form-control" id="inputGroupFile04" aria-describedby="inputGroupFileAddon04" aria-label="Upload">
        <button class="btn btn-outline-secondary" type="button" id="inputGroupFileAddon04">Submit</button>
    </div>
</form>
</body>
</html>

views.py

from django.http import HttpResponse
from django.shortcuts import render
import PyPDF2
from io import StringIO

def index(request):
    return render(request,'index.html')

def analyze(request):
    if request.method == "GET":
        #txt = request.FILES['inp'].read()  # get the uploaded file
        pdfFileObj = open(request.FILES['inp'].read(), 'rb')
        # pdfFileObj = open((request.GET.get('inp.pdf')),'rb')
        pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
        pageObj = pdfReader.getPage(0)

        content = pageObj.extractText()
        buf = StringIO(content)
        l = buf.readlines()
        while '\n' in l:
            l.remove('\n')
        i = 0
        while i < len(l):
            for j in range(len(l[i])):
                if l[i][j:j + 2] == '\n':
                    l[i] = l[i][:-1]
                j += 1
            i += 1

        d = {}
        i = 0
        while i < (len(l)):
            if ":" in l[i]:
                k = l[i].split(":")
                d[k[0]] = l[i + 1]
                i += 1
            else:
                i += 1
        params = {'ans': d}
        return render(request,'analyze.html',params)
    else:
        return HttpResponse("hello")

analyze.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Your Dict</title>
</head>
<body>
{{ ans }}
</body>
</html>

urls.py

from django.contrib import admin
from django.urls import path
from . import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.index, name='index' ),
    path('analyze', views.analyze, name='analyze')
]
Вернуться на верх