I just want to preface by saying I searched and found very similar questions, but unless I messed up, they did not work for me. Now to the question.
I am very new at using flask, and I am building a website using flask, and this is what my files look like:
flaskapp/ --> app.py & wordlcoud.py & templates (all three in the flaskapp directory)
I have a function in my wordlcoud.py file that I want to use in my app.py file. When I restart the server and try to navigate to my website, I only am shown 502 bad gateway, and when I delete the "import wordlcoud", my website loads fine.
Here is how my app.py file is set up:
from flask import Flask, render_template, redirect, url_for, request
import wordlcoud
app = Flask(__name__)
@app.route("/")
def home_function():
return render_template("home.html")
@app.route("/projects", methods=["POST", "GET"])
if flask.request.method == "POST":
wordlcoud.saveWC(q)
return redirect(url_for("/output")
else:
return render_template("projects.html")
@app.route("/output")
def image_fxn():
return render_template("output.html")
"saveWC" is the function from wordlcoud.py that I am trying to use.
I have seen to create an init .py file, but unless I put that in the wrong spot, that did not help at all.
Thank you in advance
Drew
you said that when you delete this line of code the website work
import wordlcoud
well without importinh the module this must not work as well
wordlcoud.saveWC(q)
but i think that you delete that line as well, i think that the mistake is in this line not in the import line, because the the variable q not declared before,
i hope that this help
i think
import
module_name
will import whole module
|
but try to import specific function may it will solve issue
from
module_name
importyour_function
like this -> from wordlcoud
import saveWC
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.