6

I am new in using PyCharm but I am loving it gradually. I am getting a red underline on <!DOCTYPE html> and the error is "Unexpected Token".

Why PyCharm shows it? I can't understand.

LazyOne
  • 158,824
  • 45
  • 388
  • 391

3 Answers3

6

It usually happens when you don't enable Django in Pycharm's settings. To resolve the problem:

  1. In Pycharm open Setting in File menu
  2. Select and expand Languages & Frameworks
  3. Select Django and enable it
  4. Select your Django project root
  5. Select your project setting.py file
  6. Select your project manage.py file
  7. Apply setting
DaveL17
  • 1,673
  • 7
  • 24
  • 38
Farshid Ahmadi
  • 437
  • 6
  • 23
2

PyCharm does not provide support for the Django framework in the free community edition. The best solution may be to go with another IDE (at least until support is added).

ingyhere
  • 11,818
  • 3
  • 38
  • 52
Python Dev
  • 21
  • 1
1

A simple and dirty solution is to use template semantic to prevent this false positive error. Here's an example for django 3.2.10:

Before:

<!DOCTYPE html>

After:

{{ '<' }}{{ '!DOCTYPE html>' }}
Zans
  • 1,641
  • 1
  • 10
  • 5