Как отобразить ответ HTML в скрипте Python из другого скрипта?

0

Недавно я изучил Python и программировал. Я пытаюсь написать скрипт cgi для загрузки файла в другой скрипт, который вычисляет хеш md5 и сохраняет его в базе данных sqlite.

это первый скрипт для отправки файла и текста области:

#!/usr/bin/python
# coding: utf-8
import cgi,cgitb,time

print "Content-type: text/html\r\n\r\n";
print '''
<html><head>
  <title>Files storage</title>

    </head><body style="
    background-color: f4f4f4;
    font-family: Verdana;
    font-size: 14px;
    ">
    <div id="container" style="
    border: 1px solid rgb(0,100,200);
    padding: 5px 20px;
    width: 400px;
    margin: 0 auto;
    ">
    <p><b>Select the file to upload :</b></p>
    <form method="post" action="arch0_1.py" enctype="multipart/form-data">
    <p>File: <input type="file" name="up_file"><br><p>
    <label for="description">File description (max. 255 characters) :</label><br>
    <textarea name="tag" id="description" style="margin: 2px; width: 389px; height: 108px;"></textarea><br>
    <input type="submit" name="submit" value="Upload">
    </form>
    </div>
    </body></html>
'''

На другом скрипте я обрабатываю данные и заканчиваю свой скрипт:

if fileitem.filename:
  fn = os.path.basename(fileitem.filename)
  open ('/archivages/tmp_file/' + fn, 'wb').write(fileitem.file.read())

  message = 'The file "' + fn +'" was uploaded successfully'
else:
  message = 'No files was uploaded'

print """\
    Content-Type: text/html\n
    <html>
    <body>
       <p>%s</p>
       </body>
       </html>
       """ % (message,)

Как лучший способ получить последнюю "печать" в первом скрипте для отображения текста в веб-браузере?

Теги:
cgi

1 ответ

-2

мы можем написать сообщение jquery, чтобы уловить текст ответа из результата.

  • 0
    Я нашел решение, мой заголовок был неправильным! print "Content-type: text / html \ r \ n \ r \ n" print "" "<html> <body> <p>% s </ p> </ body> </ html>" ""% ( сообщение,)

Ещё вопросы

Сообщество Overcoder
Наверх
Меню