Plain and simple, I'm aiming to have a user input their name, and select an image from the file input. With some help with my previous question, I was able to get the name to carry over to the next page, but I'm unable to get a selected image to display.
Right now, when filled out, the name and image file name are provided. Hoping to get the image file to actually display the image.
Here is my current code:
Home.html
{% extends 'base.html' %}
{% block head %}
<title>Home Page</title>
{% endblock %}
{% block body %}
<div class="content-container">
<form action="{{ url_for('result') }}" method="post">
<h2>Input your name:</h2>
<input type="text" class="user-input user mb-3" name="user">
<h2>Select your image:</h2>
<input type="file" accept="image/*" class="form-control-file"
id="formControlFile1" name="image">
<input class="btn btn-outline-primary" type="submit" value="Submit">
</form>
</div>
{% endblock %}
Result.html
{% extends 'base.html' %}
{% block head %}
<title>Result Page</title>
{% endblock %}
{% block body %}
<div class="content-container">
<h2>{{ name }}</h2>
<h2>{{ image }}</h2>
</div>
{% endblock %}
Main.py
from flask import Flask, render_template, request, url_for, redirect
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def home():
if request.method == 'POST':
user = request.form["user"]
image = request.form["image"]
return redirect(url_for('result', name=user, image=image))
return render_template('home.html')
@app.route("/result", methods=['GET', 'POST'])
def result():
name = request.form.get('user')
image = request.form.get('image')
return render_template("result.html", name=name, image=image)
if __name__ == "__main__":
app.run()
So, yeah, hopefully I explained that easy enough. User inputs name, selects image, and the goal is for the name to show and image to display on the result page. Thanks to anyone that can provide this lowly soul with guidance.