Webpack And React Image Not Found
Solution 1:
I kept overlooking where the app was running from, sorry about that.
By far the easiest solution is to set you static folder to a different folder:
app = Flask(__name__, static_folder='../static')
I just tried it, and this should work without a problem.
You can find your file here:
http://127.0.0.1:5000/static/images/smiley.png
Your bundle file will be here:
http://127.0.0.1:5000/static/dist/bundle.js
You're getting a template error because you don't have a template folder, which is normally called tempates. So make a subfolder called templates
in your server
folder. Then, don't specify the template_folder
argument in the app = Flask(..)
line, but keep it app = Flask(__name__, static_folder='../static')
.
If, for some reason, you want to seperate your static from your public files and have a /public
route as well, you might want to try the following approach:
@app.route("/public/<path:path>")
def get_public_file(path):
full_path = os.path.join('../static/dist/public/', path)
head, tail = os.path.split(full_path)
return send_from_directory(head, tail)
You can then access the smiley in the fullstack_template/static/dist/public/images/smiley.png
by going to http://127.0.0.1:5000/public/images/smiley.png
.
Post a Comment for "Webpack And React Image Not Found"