Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask PyCharm Syntax error

Tags:

flask

pycharm

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

like image 881
trollchen Avatar asked Sep 13 '26 15:09

trollchen


1 Answers

This is because PyCharm is not able to recognize the flask package or version.

Once you add new project to PyCharm -

  1. Go to File menu item
  2. Click on Settings option
  3. This will open-up the pop-up window.
  4. In the left-hand-side link list - click on the project name
  5. Click on the Project Interpreter link
  6. In the right-hand-side pane select Flask and related packages that your project needs and add/install the same.

enter image description here

like image 74
Pralhad Narsinh Sonar Avatar answered Sep 17 '26 21:09

Pralhad Narsinh Sonar