7

I'm working on a small project where it would be helpful to display trivial web pages. It's being developed in PyCharm, the pro edition.

This is an existing project, so it wasn't created as a Flask app to begin with.

I've added Flask to my requirements.txt and ensured that its installed. However, I don't get autocompletion of any Jinja templates - essentially, the HTML file I created is treated like dumb HTML.

How do I get PyCharm to recognize that I'm using Flask and to act accordingly?

IDE Screenshot

Mikey T.K.
  • 1,112
  • 18
  • 43

3 Answers3

10

You have to tell PyCharm which folders contain your templates.

  1. Go to Settings/Project: NAME/Project Structure
  2. Click on the folder containing your templates and click the purple Templates button.

It will probably warn you that no template language is specified. If that is the case

  1. go to Settings/Language & Frameworks/Python Template Languages
  2. In the combobox Template Language: select your template language (jinja?)
  3. Under Template file types select the file type (probably HTML)
Wombatz
  • 4,958
  • 1
  • 26
  • 35
0

When you create a project ( File->New Project ) to choose:

enter image description here

After the creation of the project to select the appropriate file:

enter image description here

alex10
  • 2,726
  • 3
  • 22
  • 35
0

Creating a new Flask Project will just set the python template language as Jinja2 and give you a skeleton (a web server which respond 'Hello World' to client).

Therefore, if you have a existing project, press Prefences -> Search Python Template Languages -> and now you can change it to Jinja2

Aris Chow
  • 178
  • 2
  • 6