如何使用python和HTML打开pdf文件作为链接

时间:2017-12-05 04:45:19

标签: python html

我使用python和HTML做了一个实时更新模块。我在文本区域字段中给出了链接标题,并在文本字段中获取了链接内容,当我点击链接时我成功获得了输出它显示了内容链接,我想在文本区域中给出链接标题,并在我点击链接时上传pdf文件应该打开时使用文件类型上传pdf。我不知道怎么做。请帮助我!谢谢前进:)

这是我的代码: marquee.html:

<form action="/mar" method="post" enctype=multipart/form-data>
<textarea name="Text" cols="50" rows="5">
Enter some text...
</textarea>
    <input type=file name=file>
<input type="submit" />
</form>

的.py:

import os
from flask import Flask, render_template, request
from werkzeug.utils import secure_filename

UPLOAD_FOLDER = 'C:/Users/admin/PycharmProjects/videofilter/file'
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

def allowed_file(filename):
    return '.' in filename and \
           filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS

@app.route("/")
def main():
    return render_template("marquee.html")

@app.route("/mar",methods=['POST', 'GET'])
def ma():
    if request.method == 'POST':
     a=request.form['Text']
     b=request.form['text']
     file=request.files['file']
     if file and allowed_file(file.filename):
         filename = secure_filename(file.filename)
         print filename
         file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
         # return redirect(url_for('upload_file', filename=filename))
         c=os.rename(file, 'C:/Users/admin/PycharmProjects/videofilter/file/saranya.pdf')
     return render_template("mar.html",a=a,c=c)

@app.route("/upload")
def upload():
    return render_template("upload.html")

if __name__ == "__main__":
    app.run()

mar.html:

<h1><a href="{{ c}}" target="_blank"><marquee>{{ a }}</marquee></a></h1>

0 个答案:

没有答案