checks.txt 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  1. ======================
  2. System check framework
  3. ======================
  4. .. currentmodule:: django.core.checks
  5. The system check framework is a set of static checks for validating Django
  6. projects. It detects common problems and provides hints for how to fix them.
  7. The framework is extensible so you can easily add your own checks.
  8. For details on how to add your own checks and integrate them with Django's
  9. system checks, see the :doc:`System check topic guide </topics/checks>`.
  10. API reference
  11. =============
  12. ``CheckMessage``
  13. ----------------
  14. .. class:: CheckMessage(level, msg, hint=None, obj=None, id=None)
  15. The warnings and errors raised by system checks must be instances of
  16. ``CheckMessage``. An instance encapsulates a single reportable error or
  17. warning. It also provides context and hints applicable to the message, and a
  18. unique identifier that is used for filtering purposes.
  19. Constructor arguments are:
  20. ``level``
  21. The severity of the message. Use one of the predefined values: ``DEBUG``,
  22. ``INFO``, ``WARNING``, ``ERROR``, ``CRITICAL``. If the level is greater or
  23. equal to ``ERROR``, then Django will prevent management commands from
  24. executing. Messages with level lower than ``ERROR`` (i.e. warnings) are
  25. reported to the console, but can be silenced.
  26. ``msg``
  27. A short (less than 80 characters) string describing the problem. The string
  28. should *not* contain newlines.
  29. ``hint``
  30. A single-line string providing a hint for fixing the problem. If no hint
  31. can be provided, or the hint is self-evident from the error message, the
  32. hint can be omitted, or a value of ``None`` can be used.
  33. ``obj``
  34. Optional. An object providing context for the message (for example, the
  35. model where the problem was discovered). The object should be a model,
  36. field, or manager or any other object that defines a ``__str__()`` method.
  37. The method is used while reporting all messages and its result precedes the
  38. message.
  39. ``id``
  40. Optional string. A unique identifier for the issue. Identifiers should
  41. follow the pattern ``applabel.X001``, where ``X`` is one of the letters
  42. ``CEWID``, indicating the message severity (``C`` for criticals, ``E`` for
  43. errors and so). The number can be allocated by the application, but should
  44. be unique within that application.
  45. There are subclasses to make creating messages with common levels easier. When
  46. using them you can omit the ``level`` argument because it is implied by the
  47. class name.
  48. .. class:: Debug(msg, hint=None, obj=None, id=None)
  49. .. class:: Info(msg, hint=None, obj=None, id=None)
  50. .. class:: Warning(msg, hint=None obj=None, id=None)
  51. .. class:: Error(msg, hint=None, obj=None, id=None)
  52. .. class:: Critical(msg, hint=None, obj=None, id=None)
  53. .. _system-check-builtin-tags:
  54. Builtin tags
  55. ============
  56. Django's system checks are organized using the following tags:
  57. * ``admin``: Checks of any admin site declarations.
  58. * ``async_support``: Checks asynchronous-related configuration.
  59. * ``caches``: Checks cache related configuration.
  60. * ``compatibility``: Flags potential problems with version upgrades.
  61. * ``database``: Checks database-related configuration issues. Database checks
  62. are not run by default because they do more than static code analysis as
  63. regular checks do. They are only run by the :djadmin:`migrate` command or if
  64. you specify configured database aliases using the ``--database`` option when
  65. calling the :djadmin:`check` command.
  66. * ``models``: Checks of model, field, and manager definitions.
  67. * ``security``: Checks security related configuration.
  68. * ``signals``: Checks on signal declarations and handler registrations.
  69. * ``sites``: Checks :mod:`django.contrib.sites` configuration.
  70. * ``staticfiles``: Checks :mod:`django.contrib.staticfiles` configuration.
  71. * ``templates``: Checks template related configuration.
  72. * ``translation``: Checks translation related configuration.
  73. * ``urls``: Checks URL configuration.
  74. Some checks may be registered with multiple tags.
  75. .. versionchanged:: 3.1
  76. The ``async_support`` tag was added.
  77. .. versionchanged:: 3.1
  78. The ``database`` checks are now run only for database aliases specified
  79. using the :option:`check --database` option.
  80. .. versionchanged:: 3.2
  81. The ``sites`` tag was added.
  82. Core system checks
  83. ==================
  84. Asynchronous support
  85. --------------------
  86. .. versionadded:: 3.1
  87. The following checks verify your setup for :doc:`/topics/async`:
  88. * **async.E001**: You should not set the :envvar:`DJANGO_ALLOW_ASYNC_UNSAFE`
  89. environment variable in deployment. This disables :ref:`async safety
  90. protection <async-safety>`.
  91. Backwards compatibility
  92. -----------------------
  93. Compatibility checks warn of potential problems that might occur after
  94. upgrading Django.
  95. * **2_0.W001**: Your URL pattern ``<pattern>`` has a ``route`` that contains
  96. ``(?P<``, begins with a ``^``, or ends with a ``$``. This was likely an
  97. oversight when migrating from ``url()`` to :func:`~django.urls.path`.
  98. Caches
  99. ------
  100. The following checks verify that your :setting:`CACHES` setting is correctly
  101. configured:
  102. * **caches.E001**: You must define a ``'default'`` cache in your
  103. :setting:`CACHES` setting.
  104. * **caches.W002**: Your ``<cache>`` configuration might expose your cache or
  105. lead to corruption of your data because its
  106. :setting:`LOCATION <CACHES-LOCATION>` matches/is inside/contains
  107. :setting:`MEDIA_ROOT`/:setting:`STATIC_ROOT`/:setting:`STATICFILES_DIRS`.
  108. Database
  109. --------
  110. MySQL and MariaDB
  111. ~~~~~~~~~~~~~~~~~
  112. If you're using MySQL or MariaDB, the following checks will be performed:
  113. * **mysql.E001**: MySQL/MariaDB does not allow unique ``CharField``\s to have a
  114. ``max_length`` > 255. *This check was changed to* ``mysql.W003`` *in Django
  115. 3.1 as the real maximum size depends on many factors.*
  116. * **mysql.W002**: MySQL/MariaDB Strict Mode is not set for database connection
  117. ``<alias>``. See also :ref:`mysql-sql-mode`.
  118. * **mysql.W003**: MySQL/MariaDB may not allow unique ``CharField``\s to have a
  119. ``max_length`` > 255.
  120. Model fields
  121. ------------
  122. * **fields.E001**: Field names must not end with an underscore.
  123. * **fields.E002**: Field names must not contain ``"__"``.
  124. * **fields.E003**: ``pk`` is a reserved word that cannot be used as a field
  125. name.
  126. * **fields.E004**: ``choices`` must be an iterable (e.g., a list or tuple).
  127. * **fields.E005**: ``choices`` must be an iterable returning ``(actual value,
  128. human readable name)`` tuples.
  129. * **fields.E006**: ``db_index`` must be ``None``, ``True`` or ``False``.
  130. * **fields.E007**: Primary keys must not have ``null=True``.
  131. * **fields.E008**: All ``validators`` must be callable.
  132. * **fields.E009**: ``max_length`` is too small to fit the longest value in
  133. ``choices`` (``<count>`` characters).
  134. * **fields.E010**: ``<field>`` default should be a callable instead of an
  135. instance so that it's not shared between all field instances.
  136. * **fields.E100**: ``AutoField``\s must set primary_key=True.
  137. * **fields.E110**: ``BooleanField``\s do not accept null values. *This check
  138. appeared before support for null values was added in Django 2.1.*
  139. * **fields.E120**: ``CharField``\s must define a ``max_length`` attribute.
  140. * **fields.E121**: ``max_length`` must be a positive integer.
  141. * **fields.W122**: ``max_length`` is ignored when used with
  142. ``<integer field type>``.
  143. * **fields.E130**: ``DecimalField``\s must define a ``decimal_places`` attribute.
  144. * **fields.E131**: ``decimal_places`` must be a non-negative integer.
  145. * **fields.E132**: ``DecimalField``\s must define a ``max_digits`` attribute.
  146. * **fields.E133**: ``max_digits`` must be a non-negative integer.
  147. * **fields.E134**: ``max_digits`` must be greater or equal to ``decimal_places``.
  148. * **fields.E140**: ``FilePathField``\s must have either ``allow_files`` or
  149. ``allow_folders`` set to True.
  150. * **fields.E150**: ``GenericIPAddressField``\s cannot accept blank values if
  151. null values are not allowed, as blank values are stored as nulls.
  152. * **fields.E160**: The options ``auto_now``, ``auto_now_add``, and ``default``
  153. are mutually exclusive. Only one of these options may be present.
  154. * **fields.W161**: Fixed default value provided.
  155. * **fields.W162**: ``<database>`` does not support a database index on
  156. ``<field data type>`` columns.
  157. * **fields.E170**: ``BinaryField``’s ``default`` cannot be a string. Use bytes
  158. content instead.
  159. * **fields.E180**: ``<database>`` does not support ``JSONField``\s.
  160. * **fields.E190**: ``<database>`` does not support a database collation on
  161. ``<field_type>``\s.
  162. * **fields.E900**: ``IPAddressField`` has been removed except for support in
  163. historical migrations.
  164. * **fields.W900**: ``IPAddressField`` has been deprecated. Support for it
  165. (except in historical migrations) will be removed in Django 1.9. *This check
  166. appeared in Django 1.7 and 1.8*.
  167. * **fields.W901**: ``CommaSeparatedIntegerField`` has been deprecated. Support
  168. for it (except in historical migrations) will be removed in Django 2.0. *This
  169. check appeared in Django 1.10 and 1.11*.
  170. * **fields.E901**: ``CommaSeparatedIntegerField`` is removed except for support
  171. in historical migrations.
  172. * **fields.W902**: ``FloatRangeField`` is deprecated and will be removed in
  173. Django 3.1. *This check appeared in Django 2.2 and 3.0*.
  174. * **fields.W903**: ``NullBooleanField`` is deprecated. Support for it (except
  175. in historical migrations) will be removed in Django 4.0.
  176. * **fields.W904**: ``django.contrib.postgres.fields.JSONField`` is deprecated.
  177. Support for it (except in historical migrations) will be removed in Django
  178. 4.0.
  179. File fields
  180. ~~~~~~~~~~~
  181. * **fields.E200**: ``unique`` is not a valid argument for a ``FileField``.
  182. *This check is removed in Django 1.11*.
  183. * **fields.E201**: ``primary_key`` is not a valid argument for a ``FileField``.
  184. * **fields.E202**: ``FileField``’s ``upload_to`` argument must be a relative
  185. path, not an absolute path.
  186. * **fields.E210**: Cannot use ``ImageField`` because Pillow is not installed.
  187. Related fields
  188. ~~~~~~~~~~~~~~
  189. * **fields.E300**: Field defines a relation with model ``<model>``, which is
  190. either not installed, or is abstract.
  191. * **fields.E301**: Field defines a relation with the model ``<model>`` which
  192. has been swapped out.
  193. * **fields.E302**: Accessor for field ``<field name>`` clashes with field
  194. ``<field name>``.
  195. * **fields.E303**: Reverse query name for field ``<field name>`` clashes with
  196. field ``<field name>``.
  197. * **fields.E304**: Field name ``<field name>`` clashes with accessor for
  198. ``<field name>``.
  199. * **fields.E305**: Field name ``<field name>`` clashes with reverse query name
  200. for ``<field name>``.
  201. * **fields.E306**: Related name must be a valid Python identifier or end with
  202. a ``'+'``.
  203. * **fields.E307**: The field ``<app label>.<model>.<field name>`` was declared
  204. with a lazy reference to ``<app label>.<model>``, but app ``<app label>``
  205. isn't installed or doesn't provide model ``<model>``.
  206. * **fields.E308**: Reverse query name ``<related query name>`` must not end
  207. with an underscore.
  208. * **fields.E309**: Reverse query name ``<related query name>`` must not contain
  209. ``'__'``.
  210. * **fields.E310**: No subset of the fields ``<field1>``, ``<field2>``, ... on
  211. model ``<model>`` is unique.
  212. * **fields.E311**: ``<model>.<field name>`` must be unique because it is
  213. referenced by a ``ForeignKey``.
  214. * **fields.E312**: The ``to_field`` ``<field name>`` doesn't exist on the
  215. related model ``<app label>.<model>``.
  216. * **fields.E320**: Field specifies ``on_delete=SET_NULL``, but cannot be null.
  217. * **fields.E321**: The field specifies ``on_delete=SET_DEFAULT``, but has no
  218. default value.
  219. * **fields.E330**: ``ManyToManyField``\s cannot be unique.
  220. * **fields.E331**: Field specifies a many-to-many relation through model
  221. ``<model>``, which has not been installed.
  222. * **fields.E332**: Many-to-many fields with intermediate tables must not be
  223. symmetrical. *This check appeared before Django 3.0.*
  224. * **fields.E333**: The model is used as an intermediate model by ``<model>``,
  225. but it has more than two foreign keys to ``<model>``, which is ambiguous.
  226. You must specify which two foreign keys Django should use via the
  227. ``through_fields`` keyword argument.
  228. * **fields.E334**: The model is used as an intermediate model by ``<model>``,
  229. but it has more than one foreign key from ``<model>``, which is ambiguous.
  230. You must specify which foreign key Django should use via the
  231. ``through_fields`` keyword argument.
  232. * **fields.E335**: The model is used as an intermediate model by ``<model>``,
  233. but it has more than one foreign key to ``<model>``, which is ambiguous.
  234. You must specify which foreign key Django should use via the
  235. ``through_fields`` keyword argument.
  236. * **fields.E336**: The model is used as an intermediary model by ``<model>``,
  237. but it does not have foreign key to ``<model>`` or ``<model>``.
  238. * **fields.E337**: Field specifies ``through_fields`` but does not provide the
  239. names of the two link fields that should be used for the relation through
  240. ``<model>``.
  241. * **fields.E338**: The intermediary model ``<through model>`` has no field
  242. ``<field name>``.
  243. * **fields.E339**: ``<model>.<field name>`` is not a foreign key to ``<model>``.
  244. * **fields.E340**: The field's intermediary table ``<table name>`` clashes with
  245. the table name of ``<model>``/``<model>.<field name>``.
  246. * **fields.W340**: ``null`` has no effect on ``ManyToManyField``.
  247. * **fields.W341**: ``ManyToManyField`` does not support ``validators``.
  248. * **fields.W342**: Setting ``unique=True`` on a ``ForeignKey`` has the same
  249. effect as using a ``OneToOneField``.
  250. * **fields.W343**: ``limit_choices_to`` has no effect on ``ManyToManyField``
  251. with a ``through`` model.
  252. * **fields.W344**: The field's intermediary table ``<table name>`` clashes with
  253. the table name of ``<model>``/``<model>.<field name>``.
  254. Models
  255. ------
  256. * **models.E001**: ``<swappable>`` is not of the form ``app_label.app_name``.
  257. * **models.E002**: ``<SETTING>`` references ``<model>``, which has not been
  258. installed, or is abstract.
  259. * **models.E003**: The model has two identical many-to-many relations through
  260. the intermediate model ``<app_label>.<model>``.
  261. * **models.E004**: ``id`` can only be used as a field name if the field also
  262. sets ``primary_key=True``.
  263. * **models.E005**: The field ``<field name>`` from parent model ``<model>``
  264. clashes with the field ``<field name>`` from parent model ``<model>``.
  265. * **models.E006**: The field clashes with the field ``<field name>`` from model
  266. ``<model>``.
  267. * **models.E007**: Field ``<field name>`` has column name ``<column name>``
  268. that is used by another field.
  269. * **models.E008**: ``index_together`` must be a list or tuple.
  270. * **models.E009**: All ``index_together`` elements must be lists or tuples.
  271. * **models.E010**: ``unique_together`` must be a list or tuple.
  272. * **models.E011**: All ``unique_together`` elements must be lists or tuples.
  273. * **models.E012**: ``constraints/indexes/index_together/unique_together``
  274. refers to the nonexistent field ``<field name>``.
  275. * **models.E013**: ``constraints/indexes/index_together/unique_together``
  276. refers to a ``ManyToManyField`` ``<field name>``, but ``ManyToManyField``\s
  277. are not supported for that option.
  278. * **models.E014**: ``ordering`` must be a tuple or list (even if you want to
  279. order by only one field).
  280. * **models.E015**: ``ordering`` refers to the nonexistent field, related field,
  281. or lookup ``<field name>``.
  282. * **models.E016**: ``constraints/indexes/index_together/unique_together``
  283. refers to field ``<field_name>`` which is not local to model ``<model>``.
  284. * **models.E017**: Proxy model ``<model>`` contains model fields.
  285. * **models.E018**: Autogenerated column name too long for field ``<field>``.
  286. Maximum length is ``<maximum length>`` for database ``<alias>``.
  287. * **models.E019**: Autogenerated column name too long for M2M field
  288. ``<M2M field>``. Maximum length is ``<maximum length>`` for database
  289. ``<alias>``.
  290. * **models.E020**: The ``<model>.check()`` class method is currently overridden.
  291. * **models.E021**: ``ordering`` and ``order_with_respect_to`` cannot be used
  292. together.
  293. * **models.E022**: ``<function>`` contains a lazy reference to
  294. ``<app label>.<model>``, but app ``<app label>`` isn't installed or
  295. doesn't provide model ``<model>``.
  296. * **models.E023**: The model name ``<model>`` cannot start or end with an
  297. underscore as it collides with the query lookup syntax.
  298. * **models.E024**: The model name ``<model>`` cannot contain double underscores
  299. as it collides with the query lookup syntax.
  300. * **models.E025**: The property ``<property name>`` clashes with a related
  301. field accessor.
  302. * **models.E026**: The model cannot have more than one field with
  303. ``primary_key=True``.
  304. * **models.W027**: ``<database>`` does not support check constraints.
  305. * **models.E028**: ``db_table`` ``<db_table>`` is used by multiple models:
  306. ``<model list>``.
  307. * **models.E029**: index name ``<index>`` is not unique for model ``<model>``.
  308. * **models.E030**: index name ``<index>`` is not unique among models:
  309. ``<model list>``.
  310. * **models.E031**: constraint name ``<constraint>`` is not unique for model
  311. ``<model>``.
  312. * **models.E032**: constraint name ``<constraint>`` is not unique among
  313. models: ``<model list>``.
  314. * **models.E033**: The index name ``<index>`` cannot start with an underscore
  315. or a number.
  316. * **models.E034**: The index name ``<index>`` cannot be longer than
  317. ``<max_length>`` characters.
  318. * **models.W035**: ``db_table`` ``<db_table>`` is used by multiple models:
  319. ``<model list>``.
  320. * **models.W036**: ``<database>`` does not support unique constraints with
  321. conditions.
  322. * **models.W037**: ``<database>`` does not support indexes with conditions.
  323. * **models.W038**: ``<database>`` does not support deferrable unique
  324. constraints.
  325. * **models.W039**: ``<database>`` does not support unique constraints with
  326. non-key columns.
  327. * **models.W040**: ``<database>`` does not support indexes with non-key
  328. columns.
  329. * **models.E041**: ``constraints`` refers to the joined field ``<field name>``.
  330. Security
  331. --------
  332. The security checks do not make your site secure. They do not audit code, do
  333. intrusion detection, or do anything particularly complex. Rather, they help
  334. perform an automated, low-hanging-fruit checklist, that can help you to improve
  335. your site's security.
  336. Some of these checks may not be appropriate for your particular deployment
  337. configuration. For instance, if you do your HTTP to HTTPS redirection in a load
  338. balancer, it'd be irritating to be constantly warned about not having enabled
  339. :setting:`SECURE_SSL_REDIRECT`. Use :setting:`SILENCED_SYSTEM_CHECKS` to
  340. silence unneeded checks.
  341. The following checks are run if you use the :option:`check --deploy` option:
  342. * **security.W001**: You do not have
  343. :class:`django.middleware.security.SecurityMiddleware` in your
  344. :setting:`MIDDLEWARE` so the :setting:`SECURE_HSTS_SECONDS`,
  345. :setting:`SECURE_CONTENT_TYPE_NOSNIFF`, :setting:`SECURE_BROWSER_XSS_FILTER`,
  346. :setting:`SECURE_REFERRER_POLICY`, and :setting:`SECURE_SSL_REDIRECT`
  347. settings will have no effect.
  348. * **security.W002**: You do not have
  349. :class:`django.middleware.clickjacking.XFrameOptionsMiddleware` in your
  350. :setting:`MIDDLEWARE`, so your pages will not be served with an
  351. ``'x-frame-options'`` header. Unless there is a good reason for your
  352. site to be served in a frame, you should consider enabling this
  353. header to help prevent clickjacking attacks.
  354. * **security.W003**: You don't appear to be using Django's built-in cross-site
  355. request forgery protection via the middleware
  356. (:class:`django.middleware.csrf.CsrfViewMiddleware` is not in your
  357. :setting:`MIDDLEWARE`). Enabling the middleware is the safest
  358. approach to ensure you don't leave any holes.
  359. * **security.W004**: You have not set a value for the
  360. :setting:`SECURE_HSTS_SECONDS` setting. If your entire site is served only
  361. over SSL, you may want to consider setting a value and enabling :ref:`HTTP
  362. Strict Transport Security <http-strict-transport-security>`. Be sure to read
  363. the documentation first; enabling HSTS carelessly can cause serious,
  364. irreversible problems.
  365. * **security.W005**: You have not set the
  366. :setting:`SECURE_HSTS_INCLUDE_SUBDOMAINS` setting to ``True``. Without this,
  367. your site is potentially vulnerable to attack via an insecure connection to a
  368. subdomain. Only set this to ``True`` if you are certain that all subdomains of
  369. your domain should be served exclusively via SSL.
  370. * **security.W006**: Your :setting:`SECURE_CONTENT_TYPE_NOSNIFF` setting is not
  371. set to ``True``, so your pages will not be served with an
  372. ``'X-Content-Type-Options: nosniff'`` header. You should consider enabling
  373. this header to prevent the browser from identifying content types incorrectly.
  374. * **security.W007**: Your :setting:`SECURE_BROWSER_XSS_FILTER` setting is not
  375. set to ``True``, so your pages will not be served with an
  376. ``'X-XSS-Protection: 1; mode=block'`` header. You should consider enabling
  377. this header to activate the browser's XSS filtering and help prevent XSS
  378. attacks. *This check is removed in Django 3.0 as the* ``X-XSS-Protection``
  379. *header is no longer honored by modern browsers.*
  380. * **security.W008**: Your :setting:`SECURE_SSL_REDIRECT` setting is not set to
  381. ``True``. Unless your site should be available over both SSL and non-SSL
  382. connections, you may want to either set this setting to ``True`` or configure
  383. a load balancer or reverse-proxy server to redirect all connections to HTTPS.
  384. * **security.W009**: Your :setting:`SECRET_KEY` has less than 50 characters or
  385. less than 5 unique characters. Please generate a long and random
  386. ``SECRET_KEY``, otherwise many of Django's security-critical features will be
  387. vulnerable to attack.
  388. * **security.W010**: You have :mod:`django.contrib.sessions` in your
  389. :setting:`INSTALLED_APPS` but you have not set
  390. :setting:`SESSION_COOKIE_SECURE` to ``True``. Using a secure-only session
  391. cookie makes it more difficult for network traffic sniffers to hijack user
  392. sessions.
  393. * **security.W011**: You have
  394. :class:`django.contrib.sessions.middleware.SessionMiddleware` in your
  395. :setting:`MIDDLEWARE`, but you have not set :setting:`SESSION_COOKIE_SECURE`
  396. to ``True``. Using a secure-only session cookie makes it more difficult for
  397. network traffic sniffers to hijack user sessions.
  398. * **security.W012**: :setting:`SESSION_COOKIE_SECURE` is not set to ``True``.
  399. Using a secure-only session cookie makes it more difficult for network traffic
  400. sniffers to hijack user sessions.
  401. * **security.W013**: You have :mod:`django.contrib.sessions` in your
  402. :setting:`INSTALLED_APPS`, but you have not set
  403. :setting:`SESSION_COOKIE_HTTPONLY` to ``True``. Using an ``HttpOnly`` session
  404. cookie makes it more difficult for cross-site scripting attacks to hijack user
  405. sessions.
  406. * **security.W014**: You have
  407. :class:`django.contrib.sessions.middleware.SessionMiddleware` in your
  408. :setting:`MIDDLEWARE`, but you have not set :setting:`SESSION_COOKIE_HTTPONLY`
  409. to ``True``. Using an ``HttpOnly`` session cookie makes it more difficult for
  410. cross-site scripting attacks to hijack user sessions.
  411. * **security.W015**: :setting:`SESSION_COOKIE_HTTPONLY` is not set to ``True``.
  412. Using an ``HttpOnly`` session cookie makes it more difficult for cross-site
  413. scripting attacks to hijack user sessions.
  414. * **security.W016**: :setting:`CSRF_COOKIE_SECURE` is not set to ``True``.
  415. Using a secure-only CSRF cookie makes it more difficult for network traffic
  416. sniffers to steal the CSRF token.
  417. * **security.W017**: :setting:`CSRF_COOKIE_HTTPONLY` is not set to ``True``.
  418. Using an ``HttpOnly`` CSRF cookie makes it more difficult for cross-site
  419. scripting attacks to steal the CSRF token. *This check is removed in Django
  420. 1.11 as the* :setting:`CSRF_COOKIE_HTTPONLY` *setting offers no practical
  421. benefit.*
  422. * **security.W018**: You should not have :setting:`DEBUG` set to ``True`` in
  423. deployment.
  424. * **security.W019**: You have
  425. :class:`django.middleware.clickjacking.XFrameOptionsMiddleware` in your
  426. :setting:`MIDDLEWARE`, but :setting:`X_FRAME_OPTIONS` is not set to
  427. ``'DENY'``. Unless there is a good reason for your site to serve other parts
  428. of itself in a frame, you should change it to ``'DENY'``.
  429. * **security.W020**: :setting:`ALLOWED_HOSTS` must not be empty in deployment.
  430. * **security.W021**: You have not set the
  431. :setting:`SECURE_HSTS_PRELOAD` setting to ``True``. Without this, your site
  432. cannot be submitted to the browser preload list.
  433. * **security.W022**: You have not set the :setting:`SECURE_REFERRER_POLICY`
  434. setting. Without this, your site will not send a Referrer-Policy header. You
  435. should consider enabling this header to protect user privacy.
  436. * **security.E023**: You have set the :setting:`SECURE_REFERRER_POLICY` setting
  437. to an invalid value.
  438. The following checks verify that your security-related settings are correctly
  439. configured:
  440. * **security.E100**: :setting:`DEFAULT_HASHING_ALGORITHM` must be ``'sha1'`` or
  441. ``'sha256'``.
  442. Signals
  443. -------
  444. * **signals.E001**: ``<handler>`` was connected to the ``<signal>`` signal with
  445. a lazy reference to the sender ``<app label>.<model>``, but app ``<app label>``
  446. isn't installed or doesn't provide model ``<model>``.
  447. Templates
  448. ---------
  449. The following checks verify that your :setting:`TEMPLATES` setting is correctly
  450. configured:
  451. * **templates.E001**: You have ``'APP_DIRS': True`` in your
  452. :setting:`TEMPLATES` but also specify ``'loaders'`` in ``OPTIONS``. Either
  453. remove ``APP_DIRS`` or remove the ``'loaders'`` option.
  454. * **templates.E002**: ``string_if_invalid`` in :setting:`TEMPLATES`
  455. :setting:`OPTIONS <TEMPLATES-OPTIONS>` must be a string but got: ``{value}``
  456. (``{type}``).
  457. Translation
  458. -----------
  459. The following checks are performed on your translation configuration:
  460. * **translation.E001**: You have provided an invalid value for the
  461. :setting:`LANGUAGE_CODE` setting: ``<value>``.
  462. * **translation.E002**: You have provided an invalid language code in the
  463. :setting:`LANGUAGES` setting: ``<value>``.
  464. * **translation.E003**: You have provided an invalid language code in the
  465. :setting:`LANGUAGES_BIDI` setting: ``<value>``.
  466. * **translation.E004**: You have provided a value for the
  467. :setting:`LANGUAGE_CODE` setting that is not in the :setting:`LANGUAGES`
  468. setting.
  469. URLs
  470. ----
  471. The following checks are performed on your URL configuration:
  472. * **urls.W001**: Your URL pattern ``<pattern>`` uses
  473. :func:`~django.urls.include` with a ``route`` ending with a ``$``. Remove the
  474. dollar from the ``route`` to avoid problems including URLs.
  475. * **urls.W002**: Your URL pattern ``<pattern>`` has a ``route`` beginning with
  476. a ``/``. Remove this slash as it is unnecessary. If this pattern is targeted
  477. in an :func:`~django.urls.include`, ensure the :func:`~django.urls.include`
  478. pattern has a trailing ``/``.
  479. * **urls.W003**: Your URL pattern ``<pattern>`` has a ``name``
  480. including a ``:``. Remove the colon, to avoid ambiguous namespace
  481. references.
  482. * **urls.E004**: Your URL pattern ``<pattern>`` is invalid. Ensure that
  483. ``urlpatterns`` is a list of :func:`~django.urls.path` and/or
  484. :func:`~django.urls.re_path` instances.
  485. * **urls.W005**: URL namespace ``<namespace>`` isn't unique. You may not be
  486. able to reverse all URLs in this namespace.
  487. * **urls.E006**: The :setting:`MEDIA_URL`/ :setting:`STATIC_URL` setting must
  488. end with a slash.
  489. * **urls.E007**: The custom ``handlerXXX`` view ``'path.to.view'`` does not
  490. take the correct number of arguments (…).
  491. * **urls.E008**: The custom ``handlerXXX`` view ``'path.to.view'`` could not be
  492. imported.
  493. ``contrib`` app checks
  494. ======================
  495. ``admin``
  496. ---------
  497. Admin checks are all performed as part of the ``admin`` tag.
  498. The following checks are performed on any
  499. :class:`~django.contrib.admin.ModelAdmin` (or subclass) that is registered
  500. with the admin site:
  501. * **admin.E001**: The value of ``raw_id_fields`` must be a list or tuple.
  502. * **admin.E002**: The value of ``raw_id_fields[n]`` refers to ``<field name>``,
  503. which is not an attribute of ``<model>``.
  504. * **admin.E003**: The value of ``raw_id_fields[n]`` must be a foreign key or
  505. a many-to-many field.
  506. * **admin.E004**: The value of ``fields`` must be a list or tuple.
  507. * **admin.E005**: Both ``fieldsets`` and ``fields`` are specified.
  508. * **admin.E006**: The value of ``fields`` contains duplicate field(s).
  509. * **admin.E007**: The value of ``fieldsets`` must be a list or tuple.
  510. * **admin.E008**: The value of ``fieldsets[n]`` must be a list or tuple.
  511. * **admin.E009**: The value of ``fieldsets[n]`` must be of length 2.
  512. * **admin.E010**: The value of ``fieldsets[n][1]`` must be a dictionary.
  513. * **admin.E011**: The value of ``fieldsets[n][1]`` must contain the key
  514. ``fields``.
  515. * **admin.E012**: There are duplicate field(s) in ``fieldsets[n][1]``.
  516. * **admin.E013**: ``fields[n]/fieldsets[n][m]`` cannot include the
  517. ``ManyToManyField`` ``<field name>``, because that field manually specifies a
  518. relationship model.
  519. * **admin.E014**: The value of ``exclude`` must be a list or tuple.
  520. * **admin.E015**: The value of ``exclude`` contains duplicate field(s).
  521. * **admin.E016**: The value of ``form`` must inherit from ``BaseModelForm``.
  522. * **admin.E017**: The value of ``filter_vertical`` must be a list or tuple.
  523. * **admin.E018**: The value of ``filter_horizontal`` must be a list or tuple.
  524. * **admin.E019**: The value of ``filter_vertical[n]/filter_horizontal[n]``
  525. refers to ``<field name>``, which is not an attribute of ``<model>``.
  526. * **admin.E020**: The value of ``filter_vertical[n]/filter_horizontal[n]``
  527. must be a many-to-many field.
  528. * **admin.E021**: The value of ``radio_fields`` must be a dictionary.
  529. * **admin.E022**: The value of ``radio_fields`` refers to ``<field name>``,
  530. which is not an attribute of ``<model>``.
  531. * **admin.E023**: The value of ``radio_fields`` refers to ``<field name>``,
  532. which is not a ``ForeignKey``, and does not have a ``choices`` definition.
  533. * **admin.E024**: The value of ``radio_fields[<field name>]`` must be either
  534. ``admin.HORIZONTAL`` or ``admin.VERTICAL``.
  535. * **admin.E025**: The value of ``view_on_site`` must be either a callable or a
  536. boolean value.
  537. * **admin.E026**: The value of ``prepopulated_fields`` must be a dictionary.
  538. * **admin.E027**: The value of ``prepopulated_fields`` refers to
  539. ``<field name>``, which is not an attribute of ``<model>``.
  540. * **admin.E028**: The value of ``prepopulated_fields`` refers to
  541. ``<field name>``, which must not be a ``DateTimeField``, a ``ForeignKey``,
  542. a ``OneToOneField``, or a ``ManyToManyField`` field.
  543. * **admin.E029**: The value of ``prepopulated_fields[<field name>]`` must be a
  544. list or tuple.
  545. * **admin.E030**: The value of ``prepopulated_fields`` refers to
  546. ``<field name>``, which is not an attribute of ``<model>``.
  547. * **admin.E031**: The value of ``ordering`` must be a list or tuple.
  548. * **admin.E032**: The value of ``ordering`` has the random ordering marker
  549. ``?``, but contains other fields as well.
  550. * **admin.E033**: The value of ``ordering`` refers to ``<field name>``, which
  551. is not an attribute of ``<model>``.
  552. * **admin.E034**: The value of ``readonly_fields`` must be a list or tuple.
  553. * **admin.E035**: The value of ``readonly_fields[n]`` is not a callable, an
  554. attribute of ``<ModelAdmin class>``, or an attribute of ``<model>``.
  555. * **admin.E036**: The value of ``autocomplete_fields`` must be a list or tuple.
  556. * **admin.E037**: The value of ``autocomplete_fields[n]`` refers to
  557. ``<field name>``, which is not an attribute of ``<model>``.
  558. * **admin.E038**: The value of ``autocomplete_fields[n]`` must be a foreign
  559. key or a many-to-many field.
  560. * **admin.E039**: An admin for model ``<model>`` has to be registered to be
  561. referenced by ``<modeladmin>.autocomplete_fields``.
  562. * **admin.E040**: ``<modeladmin>`` must define ``search_fields``, because
  563. it's referenced by ``<other_modeladmin>.autocomplete_fields``.
  564. ``ModelAdmin``
  565. ~~~~~~~~~~~~~~
  566. The following checks are performed on any
  567. :class:`~django.contrib.admin.ModelAdmin` that is registered
  568. with the admin site:
  569. * **admin.E101**: The value of ``save_as`` must be a boolean.
  570. * **admin.E102**: The value of ``save_on_top`` must be a boolean.
  571. * **admin.E103**: The value of ``inlines`` must be a list or tuple.
  572. * **admin.E104**: ``<InlineModelAdmin class>`` must inherit from
  573. ``InlineModelAdmin``.
  574. * **admin.E105**: ``<InlineModelAdmin class>`` must have a ``model`` attribute.
  575. * **admin.E106**: The value of ``<InlineModelAdmin class>.model`` must be a
  576. ``Model``.
  577. * **admin.E107**: The value of ``list_display`` must be a list or tuple.
  578. * **admin.E108**: The value of ``list_display[n]`` refers to ``<label>``,
  579. which is not a callable, an attribute of ``<ModelAdmin class>``, or an
  580. attribute or method on ``<model>``.
  581. * **admin.E109**: The value of ``list_display[n]`` must not be a
  582. ``ManyToManyField`` field.
  583. * **admin.E110**: The value of ``list_display_links`` must be a list, a tuple,
  584. or ``None``.
  585. * **admin.E111**: The value of ``list_display_links[n]`` refers to ``<label>``,
  586. which is not defined in ``list_display``.
  587. * **admin.E112**: The value of ``list_filter`` must be a list or tuple.
  588. * **admin.E113**: The value of ``list_filter[n]`` must inherit from
  589. ``ListFilter``.
  590. * **admin.E114**: The value of ``list_filter[n]`` must not inherit from
  591. ``FieldListFilter``.
  592. * **admin.E115**: The value of ``list_filter[n][1]`` must inherit from
  593. ``FieldListFilter``.
  594. * **admin.E116**: The value of ``list_filter[n]`` refers to ``<label>``,
  595. which does not refer to a Field.
  596. * **admin.E117**: The value of ``list_select_related`` must be a boolean,
  597. tuple or list.
  598. * **admin.E118**: The value of ``list_per_page`` must be an integer.
  599. * **admin.E119**: The value of ``list_max_show_all`` must be an integer.
  600. * **admin.E120**: The value of ``list_editable`` must be a list or tuple.
  601. * **admin.E121**: The value of ``list_editable[n]`` refers to ``<label>``,
  602. which is not an attribute of ``<model>``.
  603. * **admin.E122**: The value of ``list_editable[n]`` refers to ``<label>``,
  604. which is not contained in ``list_display``.
  605. * **admin.E123**: The value of ``list_editable[n]`` cannot be in both
  606. ``list_editable`` and ``list_display_links``.
  607. * **admin.E124**: The value of ``list_editable[n]`` refers to the first field
  608. in ``list_display`` (``<label>``), which cannot be used unless
  609. ``list_display_links`` is set.
  610. * **admin.E125**: The value of ``list_editable[n]`` refers to ``<field name>``,
  611. which is not editable through the admin.
  612. * **admin.E126**: The value of ``search_fields`` must be a list or tuple.
  613. * **admin.E127**: The value of ``date_hierarchy`` refers to ``<field name>``,
  614. which does not refer to a Field.
  615. * **admin.E128**: The value of ``date_hierarchy`` must be a ``DateField`` or
  616. ``DateTimeField``.
  617. * **admin.E129**: ``<modeladmin>`` must define a ``has_<foo>_permission()``
  618. method for the ``<action>`` action.
  619. * **admin.E130**: ``__name__`` attributes of actions defined in
  620. ``<modeladmin>`` must be unique. Name ``<name>`` is not unique.
  621. ``InlineModelAdmin``
  622. ~~~~~~~~~~~~~~~~~~~~
  623. The following checks are performed on any
  624. :class:`~django.contrib.admin.InlineModelAdmin` that is registered as an
  625. inline on a :class:`~django.contrib.admin.ModelAdmin`.
  626. * **admin.E201**: Cannot exclude the field ``<field name>``, because it is the
  627. foreign key to the parent model ``<app_label>.<model>``.
  628. * **admin.E202**: ``<model>`` has no ``ForeignKey`` to ``<parent model>``./
  629. ``<model>`` has more than one ``ForeignKey`` to ``<parent model>``. You must
  630. specify a ``fk_name`` attribute.
  631. * **admin.E203**: The value of ``extra`` must be an integer.
  632. * **admin.E204**: The value of ``max_num`` must be an integer.
  633. * **admin.E205**: The value of ``min_num`` must be an integer.
  634. * **admin.E206**: The value of ``formset`` must inherit from
  635. ``BaseModelFormSet``.
  636. ``GenericInlineModelAdmin``
  637. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  638. The following checks are performed on any
  639. :class:`~django.contrib.contenttypes.admin.GenericInlineModelAdmin` that is
  640. registered as an inline on a :class:`~django.contrib.admin.ModelAdmin`.
  641. * **admin.E301**: ``'ct_field'`` references ``<label>``, which is not a field
  642. on ``<model>``.
  643. * **admin.E302**: ``'ct_fk_field'`` references ``<label>``, which is not a
  644. field on ``<model>``.
  645. * **admin.E303**: ``<model>`` has no ``GenericForeignKey``.
  646. * **admin.E304**: ``<model>`` has no ``GenericForeignKey`` using content type
  647. field ``<field name>`` and object ID field ``<field name>``.
  648. ``AdminSite``
  649. ~~~~~~~~~~~~~
  650. The following checks are performed on the default
  651. :class:`~django.contrib.admin.AdminSite`:
  652. * **admin.E401**: :mod:`django.contrib.contenttypes` must be in
  653. :setting:`INSTALLED_APPS` in order to use the admin application.
  654. * **admin.E402**: :mod:`django.contrib.auth.context_processors.auth`
  655. must be enabled in :class:`~django.template.backends.django.DjangoTemplates`
  656. (:setting:`TEMPLATES`) if using the default auth backend in order to use the
  657. admin application.
  658. * **admin.E403**: A :class:`django.template.backends.django.DjangoTemplates`
  659. instance must be configured in :setting:`TEMPLATES` in order to use the
  660. admin application.
  661. * **admin.E404**: ``django.contrib.messages.context_processors.messages``
  662. must be enabled in :class:`~django.template.backends.django.DjangoTemplates`
  663. (:setting:`TEMPLATES`) in order to use the admin application.
  664. * **admin.E405**: :mod:`django.contrib.auth` must be in
  665. :setting:`INSTALLED_APPS` in order to use the admin application.
  666. * **admin.E406**: :mod:`django.contrib.messages` must be in
  667. :setting:`INSTALLED_APPS` in order to use the admin application.
  668. * **admin.E408**:
  669. :class:`django.contrib.auth.middleware.AuthenticationMiddleware` must be in
  670. :setting:`MIDDLEWARE` in order to use the admin application.
  671. * **admin.E409**: :class:`django.contrib.messages.middleware.MessageMiddleware`
  672. must be in :setting:`MIDDLEWARE` in order to use the admin application.
  673. * **admin.E410**: :class:`django.contrib.sessions.middleware.SessionMiddleware`
  674. must be in :setting:`MIDDLEWARE` in order to use the admin application.
  675. * **admin.W411**: ``django.template.context_processors.request`` must be
  676. enabled in :class:`~django.template.backends.django.DjangoTemplates`
  677. (:setting:`TEMPLATES`) in order to use the admin navigation sidebar.
  678. ``auth``
  679. --------
  680. * **auth.E001**: ``REQUIRED_FIELDS`` must be a list or tuple.
  681. * **auth.E002**: The field named as the ``USERNAME_FIELD`` for a custom user
  682. model must not be included in ``REQUIRED_FIELDS``.
  683. * **auth.E003**: ``<field>`` must be unique because it is named as the
  684. ``USERNAME_FIELD``.
  685. * **auth.W004**: ``<field>`` is named as the ``USERNAME_FIELD``, but it is not
  686. unique.
  687. * **auth.E005**: The permission codenamed ``<codename>`` clashes with a builtin
  688. permission for model ``<model>``.
  689. * **auth.E006**: The permission codenamed ``<codename>`` is duplicated for model
  690. ``<model>``.
  691. * **auth.E007**: The :attr:`verbose_name
  692. <django.db.models.Options.verbose_name>` of model ``<model>`` must be at most
  693. 244 characters for its builtin permission names
  694. to be at most 255 characters.
  695. * **auth.E008**: The permission named ``<name>`` of model ``<model>`` is longer
  696. than 255 characters.
  697. * **auth.C009**: ``<User model>.is_anonymous`` must be an attribute or property
  698. rather than a method. Ignoring this is a security issue as anonymous users
  699. will be treated as authenticated!
  700. * **auth.C010**: ``<User model>.is_authenticated`` must be an attribute or
  701. property rather than a method. Ignoring this is a security issue as anonymous
  702. users will be treated as authenticated!
  703. * **auth.E011**: The name of model ``<model>`` must be at most 93 characters
  704. for its builtin permission names to be at most 100 characters.
  705. * **auth.E012**: The permission codenamed ``<codename>`` of model ``<model>``
  706. is longer than 100 characters.
  707. ``contenttypes``
  708. ----------------
  709. The following checks are performed when a model contains a
  710. :class:`~django.contrib.contenttypes.fields.GenericForeignKey` or
  711. :class:`~django.contrib.contenttypes.fields.GenericRelation`:
  712. * **contenttypes.E001**: The ``GenericForeignKey`` object ID references the
  713. nonexistent field ``<field>``.
  714. * **contenttypes.E002**: The ``GenericForeignKey`` content type references the
  715. nonexistent field ``<field>``.
  716. * **contenttypes.E003**: ``<field>`` is not a ``ForeignKey``.
  717. * **contenttypes.E004**: ``<field>`` is not a ``ForeignKey`` to
  718. ``contenttypes.ContentType``.
  719. * **contenttypes.E005**: Model names must be at most 100 characters.
  720. ``postgres``
  721. ------------
  722. The following checks are performed on :mod:`django.contrib.postgres` model
  723. fields:
  724. * **postgres.E001**: Base field for array has errors: ...
  725. * **postgres.E002**: Base field for array cannot be a related field.
  726. * **postgres.E003**: ``<field>`` default should be a callable instead of an
  727. instance so that it's not shared between all field instances. *This check was
  728. changed to* ``fields.E010`` *in Django 3.1*.
  729. ``sites``
  730. ---------
  731. The following checks are performed on any model using a
  732. :class:`~django.contrib.sites.managers.CurrentSiteManager`:
  733. * **sites.E001**: ``CurrentSiteManager`` could not find a field named
  734. ``<field name>``.
  735. * **sites.E002**: ``CurrentSiteManager`` cannot use ``<field>`` as it is not a
  736. foreign key or a many-to-many field.
  737. The following checks verify that :mod:`django.contrib.sites` is correctly
  738. configured:
  739. * **sites.E101**: The :setting:`SITE_ID` setting must be an integer.
  740. ``staticfiles``
  741. ---------------
  742. The following checks verify that :mod:`django.contrib.staticfiles` is correctly
  743. configured:
  744. * **staticfiles.E001**: The :setting:`STATICFILES_DIRS` setting is not a tuple
  745. or list.
  746. * **staticfiles.E002**: The :setting:`STATICFILES_DIRS` setting should not
  747. contain the :setting:`STATIC_ROOT` setting.
  748. * **staticfiles.E003**: The prefix ``<prefix>`` in the
  749. :setting:`STATICFILES_DIRS` setting must not end with a slash.