Hi,
I'm not new to Python, but I'm just a hoobyst and I'm completely new to web dev, Flask and Python Anywhere.
I want to make a web app do deal with PDF files uploaded by users. My first goal is to simply let the user upload a PDF, then show it in the browser.
I made the code below, but I'm receiving the message below, what am I doing wrong?
Not Found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
UPDATE: I've figured it. The code below is updated and working!
from flask import Flask, render_template, request
app = Flask(__name__)
app.config["DEBUG"] = True
BASE_DIR = os.path.dirname(__file__)
PUBLIC_ROOT = os.path.join(BASE_DIR, "public")
@app.route("/", methods=["GET", "POST"])
def main():
if request.method == "POST":
file = request.files["input_file"]
if not file:
return'''
<html>
<body>
<p>NO FILE</p>
</body>
</html>
'''
filename = secure_filename(file.filename)
file.save(os.path.join("/home/Saitodepaula/public/", filename))
return'''
<html>
<body>
<p>
<a href={} target = "_blank">
<button type="button">Abrir</button>
</a>
</p>
<p>
<a href={} Download>
<button type="button">Download</button>
</a>
</p>
<p>
<a href="">
<button type="button">Send another file</button>
</a>
</p>
</body>
</html>
'''.format("https://saitodepaula.pythonanywhere.com/public/" + filename, "https://saitodepaula.pythonanywhere.com/public/" + filename)
return '''
<html>
<body>
<p>Select a file:</p>
<form method="post" action="." enctype = multipart/form-data>
<p><input type="file" name="input_file" accept=".pdf" ></p>
<p><input type="submit" value="Process the file" /></p>
</form>
</body>
</html>
'''