Reputation: 78
I've just started developing a new application using Flask and PyCharm as my IDE. I've encountered a problem which is driving me crazy.
Here is the code. I'll spare use all the import part and so on, I'll show only the routes that cause problems.
@app.route("/")
def home():
return render_template("home.html")
@app.route("/login/")
def login():
return "foo"
The first route works without a problem. However on the first line of the second route, PyCharm gives me an error message '"@" or "def" expected'. This breaks the autoindent and the auto completion features.
But the code runs without a problem.
Can anyone tell me how to fix this?
Thank you
Upvotes: 3
Views: 893
Reputation: 3616
What worked for me was (I was missing pycharm's python environment
dependencies for python)
If you don't already have a requirements file for your project.
Navigate to your project & this on your command line (as I used a venv
virtual environment):
(venv)$ pip freeze > requirements.txt
Then Open your pycharm and open the requirements file, wait a second or two and a pop up notification will show up at the top showing you are missing dependencies and will provide you a click here
to install.
After that I had no issues.
Upvotes: 0
Reputation: 1454
This is because PyCharm is not able to recognize the flask package or version.
Once you add new project to PyCharm -
File
menu itemSettings
optionProject Interpreter
linkFlask
and related packages
that your project needs and add/install the same.Upvotes: 1