settings.rst 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937
  1. ==============================
  2. Configuring Django for Wagtail
  3. ==============================
  4. To install Wagtail completely from scratch, create a new Django project and an app within that project. For instructions on these tasks, see :doc:`Writing your first Django app <django:intro/tutorial01>`. Your project directory will look like the following::
  5. myproject/
  6. myproject/
  7. __init__.py
  8. settings.py
  9. urls.py
  10. wsgi.py
  11. myapp/
  12. __init__.py
  13. models.py
  14. tests.py
  15. admin.py
  16. views.py
  17. manage.py
  18. From your app directory, you can safely remove ``admin.py`` and ``views.py``, since Wagtail will provide this functionality for your models. Configuring Django to load Wagtail involves adding modules and variables to ``settings.py`` and URL configuration to ``urls.py``. For a more complete view of what's defined in these files, see :doc:`Django Settings <django:topics/settings>` and :doc:`Django URL Dispatcher <django:topics/http/urls>`.
  19. What follows is a settings reference which skips many boilerplate Django settings. If you just want to get your Wagtail install up quickly without fussing with settings at the moment, see :ref:`complete_example_config`.
  20. Middleware (``settings.py``)
  21. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  22. .. code-block:: python
  23. MIDDLEWARE = [
  24. 'django.contrib.sessions.middleware.SessionMiddleware',
  25. 'django.middleware.common.CommonMiddleware',
  26. 'django.middleware.csrf.CsrfViewMiddleware',
  27. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  28. 'django.contrib.messages.middleware.MessageMiddleware',
  29. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  30. 'django.middleware.security.SecurityMiddleware',
  31. 'wagtail.core.middleware.SiteMiddleware',
  32. 'wagtail.contrib.redirects.middleware.RedirectMiddleware',
  33. ]
  34. Wagtail requires several common Django middleware modules to work and cover basic security. Wagtail provides its own middleware to cover these tasks:
  35. ``SiteMiddleware``
  36. Wagtail routes pre-defined hosts to pages within the Wagtail tree using this middleware.
  37. ``RedirectMiddleware``
  38. Wagtail provides a simple interface for adding arbitrary redirects to your site and this module makes it happen.
  39. Apps (``settings.py``)
  40. ~~~~~~~~~~~~~~~~~~~~~~
  41. .. code-block:: python
  42. INSTALLED_APPS = [
  43. 'myapp', # your own app
  44. 'wagtail.contrib.forms',
  45. 'wagtail.contrib.redirects',
  46. 'wagtail.embeds',
  47. 'wagtail.sites',
  48. 'wagtail.users',
  49. 'wagtail.snippets',
  50. 'wagtail.documents',
  51. 'wagtail.images',
  52. 'wagtail.search',
  53. 'wagtail.admin',
  54. 'wagtail.core',
  55. 'taggit',
  56. 'modelcluster',
  57. 'django.contrib.auth',
  58. 'django.contrib.contenttypes',
  59. 'django.contrib.sessions',
  60. 'django.contrib.messages',
  61. 'django.contrib.staticfiles',
  62. ]
  63. Wagtail requires several Django app modules, third-party apps, and defines several apps of its own. Wagtail was built to be modular, so many Wagtail apps can be omitted to suit your needs. Your own app (here ``myapp``) is where you define your models, templates, static assets, template tags, and other custom functionality for your site.
  64. Wagtail Apps
  65. ------------
  66. ``wagtailcore``
  67. The core functionality of Wagtail, such as the ``Page`` class, the Wagtail tree, and model fields.
  68. ``wagtailadmin``
  69. The administration interface for Wagtail, including page edit handlers.
  70. ``wagtaildocs``
  71. The Wagtail document content type.
  72. ``wagtailsnippets``
  73. Editing interface for non-Page models and objects. See :ref:`Snippets`.
  74. ``wagtailusers``
  75. User editing interface.
  76. ``wagtailimages``
  77. The Wagtail image content type.
  78. ``wagtailembeds``
  79. Module governing oEmbed and Embedly content in Wagtail rich text fields. See :ref:`inserting_videos`.
  80. ``wagtailsearch``
  81. Search framework for Page content. See :ref:`wagtailsearch`.
  82. ``wagtailredirects``
  83. Admin interface for creating arbitrary redirects on your site.
  84. ``wagtailforms``
  85. Models for creating forms on your pages and viewing submissions. See :ref:`form_builder`.
  86. Third-Party Apps
  87. ----------------
  88. ``taggit``
  89. Tagging framework for Django. This is used internally within Wagtail for image and document tagging and is available for your own models as well. See :ref:`tagging` for a Wagtail model recipe or the `Taggit Documentation`_.
  90. .. _Taggit Documentation: https://django-taggit.readthedocs.org/en/latest/index.html
  91. ``modelcluster``
  92. Extension of Django ForeignKey relation functionality, which is used in Wagtail pages for on-the-fly related object creation. For more information, see :ref:`inline_panels` or `the django-modelcluster github project page`_.
  93. .. _the django-modelcluster github project page: https://github.com/torchbox/django-modelcluster
  94. Settings Variables (``settings.py``)
  95. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  96. Wagtail makes use of the following settings, in addition to :doc:`Django's core settings <ref/settings>`:
  97. Site Name
  98. ---------
  99. .. code-block:: python
  100. WAGTAIL_SITE_NAME = 'Stark Industries Skunkworks'
  101. This is the human-readable name of your Wagtail install which welcomes users upon login to the Wagtail admin.
  102. .. _append_slash:
  103. Append Slash
  104. ------------
  105. .. code-block:: python
  106. # Don't add a trailing slash to Wagtail-served URLs
  107. WAGTAIL_APPEND_SLASH = False
  108. Similar to Django's ``APPEND_SLASH``, this setting controls how Wagtail will handle requests that don't end in a trailing slash.
  109. When ``WAGTAIL_APPEND_SLASH`` is ``True`` (default), requests to Wagtail pages which omit a trailing slash will be redirected by Django's :class:`~django.middleware.common.CommonMiddleware` to a URL with a trailing slash.
  110. When ``WAGTAIL_APPEND_SLASH`` is ``False``, requests to Wagtail pages will be served both with and without trailing slashes. Page links generated by Wagtail, however, will not include trailing slashes.
  111. .. note::
  112. If you use the ``False`` setting, keep in mind that serving your pages both with and without slashes may affect search engines' ability to index your site. See `this Google Webmaster Blog post`_ for more details.
  113. .. _this Google Webmaster Blog post: https://webmasters.googleblog.com/2010/04/to-slash-or-not-to-slash.html
  114. Search
  115. ------
  116. .. code-block:: python
  117. WAGTAILSEARCH_BACKENDS = {
  118. 'default': {
  119. 'BACKEND': 'wagtail.search.backends.elasticsearch2',
  120. 'INDEX': 'myapp'
  121. }
  122. }
  123. Define a search backend. For a full explanation, see :ref:`wagtailsearch_backends`.
  124. .. code-block:: python
  125. WAGTAILSEARCH_RESULTS_TEMPLATE = 'myapp/search_results.html'
  126. WAGTAILSEARCH_RESULTS_TEMPLATE_AJAX = 'myapp/includes/search_listing.html'
  127. Override the templates used by the search front-end views.
  128. .. _wagtailsearch_hits_max_age:
  129. .. code-block:: python
  130. WAGTAILSEARCH_HITS_MAX_AGE = 14
  131. Set the number of days (default 7) that search query logs are kept for; these are used to identify popular search terms for :ref:`promoted search results <editors-picks>`. Queries older than this will be removed by the :ref:`search_garbage_collect` command.
  132. Embeds
  133. ------
  134. Wagtail supports generating embed code from URLs to content on an external
  135. providers such as Youtube or Twitter. By default, Wagtail will fetch the embed
  136. code directly from the relevant provider's site using the oEmbed protocol.
  137. Wagtail has a builtin list of the most common providers.
  138. The embeds fetching can be fully configured using the ``WAGTAILEMBEDS_FINDERS``
  139. setting. This is fully documented in :ref:`configuring_embed_finders`.
  140. Dashboard
  141. ---------
  142. .. code-block:: python
  143. WAGTAILADMIN_RECENT_EDITS_LIMIT = 5
  144. This setting lets you change the number of items shown at 'Your most recent edits' on the dashboard.
  145. .. code-block:: python
  146. WAGTAILADMIN_USER_LOGIN_FORM = 'users.forms.LoginForm'
  147. Allows the default ``LoginForm`` to be extended with extra fields.
  148. .. _wagtail_gravatar_provider_url:
  149. .. code-block:: python
  150. WAGTAIL_GRAVATAR_PROVIDER_URL = '//www.gravatar.com/avatar'
  151. If a user has not uploaded a profile picture, Wagtail will look for an avatar linked to their email address on gravatar.com. This setting allows you to specify an alternative provider such as like robohash.org, or can be set to ``None`` to disable the use of remote avatars completely.
  152. .. _wagtail_moderation_enabled:
  153. .. code-block:: python
  154. WAGTAIL_MODERATION_ENABLED = True
  155. Changes whether the Submit for Moderation button is displayed in the action menu.
  156. Images
  157. ------
  158. .. code-block:: python
  159. WAGTAILIMAGES_IMAGE_MODEL = 'myapp.MyImage'
  160. This setting lets you provide your own image model for use in Wagtail, which might extend the built-in ``AbstractImage`` class or replace it entirely.
  161. .. code-block:: python
  162. WAGTAILIMAGES_MAX_UPLOAD_SIZE = 20 * 1024 * 1024 # i.e. 20MB
  163. This setting lets you override the maximum upload size for images (in bytes). If omitted, Wagtail will fall back to using its 10MB default value.
  164. .. code-block:: python
  165. WAGTAILIMAGES_MAX_IMAGE_PIXELS = 128000000 # i.e. 128 megapixels
  166. This setting lets you override the maximum number of pixels an image can have. If omitted, Wagtail will fall back to using its 128 megapixels default value. The pixel count takes animation frames into account - for example, a 25-frame animation of size 100x100 is considered to have 100 * 100 * 25 = 250000 pixels.
  167. .. code-block:: python
  168. WAGTAILIMAGES_FEATURE_DETECTION_ENABLED = True
  169. This setting enables feature detection once OpenCV is installed, see all details on the :ref:`image_feature_detection` documentation.
  170. .. code-block:: python
  171. WAGTAILIMAGES_INDEX_PAGE_SIZE = 20
  172. Specifies the number of images per page shown on the main Images listing in the Wagtail admin.
  173. .. code-block:: python
  174. WAGTAILIMAGES_USAGE_PAGE_SIZE = 20
  175. Specifies the number of items per page shown when viewing an image's usage (see :ref:`WAGTAIL_USAGE_COUNT_ENABLED <WAGTAIL_USAGE_COUNT_ENABLED>`).
  176. .. code-block:: python
  177. WAGTAILIMAGES_CHOOSER_PAGE_SIZE = 12
  178. Specifies the number of images shown per page in the image chooser modal.
  179. Documents
  180. ---------
  181. .. _wagtaildocs_serve_method:
  182. .. code-block:: python
  183. WAGTAILDOCS_SERVE_METHOD = 'redirect'
  184. Determines how document downloads will be linked to and served. Normally, requests for documents are sent through a Django view, to perform permission checks (see :ref:`image_document_permissions`) and potentially other housekeeping tasks such as hit counting. To fully protect against users bypassing this check, it needs to happen in the same request where the document is served; however, this incurs a performance hit as the document then needs to be served by the Django server. In particular, this cancels out much of the benefit of hosting documents on external storage, such as S3 or a CDN.
  185. For this reason, Wagtail provides a number of serving methods which trade some of the strictness of the permission check for performance:
  186. * ``'direct'`` - links to documents point directly to the URL provided by the underlying storage, bypassing the Django view that provides the permission check. This is most useful when deploying sites as fully static HTML (e.g. using `wagtail-bakery <https://github.com/wagtail/wagtail-bakery>`_ or `Gatsby <https://www.gatsbyjs.org/>`_).
  187. * ``'redirect'`` - links to documents point to a Django view which will check the user's permission; if successful, it will redirect to the URL provided by the underlying storage to allow the document to be downloaded. This is most suitable for remote storage backends such as S3, as it allows the document to be served independently of the Django server. Note that if a user is able to guess the latter URL, they will be able to bypass the permission check; some storage backends may provide configuration options to generate a random or short-lived URL to mitigate this.
  188. * ``'serve_view'`` - links to documents point to a Django view which both checks the user's permission, and serves the document. Serving will be handled by `django-sendfile <https://github.com/johnsensible/django-sendfile>`_, if this is installed and supported by your server configuration, or as a streaming response from Django if not. When using this method, it is recommended that you configure your webserver to *disallow* serving documents directly from their location under ``MEDIA_ROOT``, as this would provide a way to bypass the permission check.
  189. If ``WAGTAILDOCS_SERVE_METHOD`` is unspecified or set to ``None``, the default method is ``'redirect'`` when a remote storage backend is in use (i.e. one that exposes a URL but not a local filesystem path), and ``'serve_view'`` otherwise. Finally, some storage backends may not expose a URL at all; in this case, serving will proceed as for ``'serve_view'``.
  190. Password Management
  191. -------------------
  192. .. code-block:: python
  193. WAGTAIL_PASSWORD_MANAGEMENT_ENABLED = True
  194. This specifies whether users are allowed to change their passwords (enabled by default).
  195. .. code-block:: python
  196. WAGTAIL_PASSWORD_RESET_ENABLED = True
  197. This specifies whether users are allowed to reset their passwords. Defaults to the same as ``WAGTAIL_PASSWORD_MANAGEMENT_ENABLED``.
  198. .. code-block:: python
  199. WAGTAILUSERS_PASSWORD_ENABLED = True
  200. This specifies whether password fields are shown when creating or editing users through Settings -> Users (enabled by default). Set this to False (along with ``WAGTAIL_PASSWORD_MANAGEMENT_ENABLED`` and ``WAGTAIL_PASSWORD_RESET_ENABLED``) if your users are authenticated through an external system such as LDAP.
  201. .. code-block:: python
  202. WAGTAILUSERS_PASSWORD_REQUIRED = True
  203. This specifies whether password is a required field when creating a new user. True by default; ignored if ``WAGTAILUSERS_PASSWORD_ENABLED`` is false. If this is set to False, and the password field is left blank when creating a user, then that user will have no usable password; in order to log in, they will have to reset their password (if ``WAGTAIL_PASSWORD_RESET_ENABLED`` is True) or use an alternative authentication system such as LDAP (if one is set up).
  204. .. code-block:: python
  205. WAGTAIL_EMAIL_MANAGEMENT_ENABLED = True
  206. This specifies whether users are allowed to change their email (enabled by default).
  207. .. _email_notifications:
  208. Email Notifications
  209. -------------------
  210. .. code-block:: python
  211. WAGTAILADMIN_NOTIFICATION_FROM_EMAIL = 'wagtail@myhost.io'
  212. Wagtail sends email notifications when content is submitted for moderation, and when the content is accepted or rejected. This setting lets you pick which email address these automatic notifications will come from. If omitted, Django will fall back to using the ``DEFAULT_FROM_EMAIL`` variable if set, and ``webmaster@localhost`` if not.
  213. .. code-block:: python
  214. WAGTAILADMIN_NOTIFICATION_USE_HTML = True
  215. Notification emails are sent in `text/plain` by default, change this to use HTML formatting.
  216. .. code-block:: python
  217. WAGTAILADMIN_NOTIFICATION_INCLUDE_SUPERUSERS = False
  218. Notification emails are sent to moderators and superusers by default. You can change this to exclude superusers and only notify moderators.
  219. .. _update_notifications:
  220. Wagtail update notifications
  221. ----------------------------
  222. .. code-block:: python
  223. WAGTAIL_ENABLE_UPDATE_CHECK = True
  224. For admins only, Wagtail performs a check on the dashboard to see if newer releases are available. This also provides the Wagtail team with the hostname of your Wagtail site. If you'd rather not receive update notifications, or if you'd like your site to remain unknown, you can disable it with this setting.
  225. Private pages / documents
  226. -------------------------
  227. .. code-block:: python
  228. PASSWORD_REQUIRED_TEMPLATE = 'myapp/password_required.html'
  229. This is the path to the Django template which will be used to display the "password required" form when a user accesses a private page. For more details, see the :ref:`private_pages` documentation.
  230. .. code-block:: python
  231. DOCUMENT_PASSWORD_REQUIRED_TEMPLATE = 'myapp/document_password_required.html'
  232. As above, but for password restrictions on documents. For more details, see the :ref:`private_pages` documentation.
  233. Login page
  234. ----------
  235. The basic login page can be customised with a custom template.
  236. .. code-block:: python
  237. WAGTAIL_FRONTEND_LOGIN_TEMPLATE = 'myapp/login.html'
  238. Or the login page can be a redirect to an external or internal URL.
  239. .. code-block:: python
  240. WAGTAIL_FRONTEND_LOGIN_URL = '/accounts/login/'
  241. For more details, see the :ref:`login_page` documentation.
  242. Case-Insensitive Tags
  243. ---------------------
  244. .. code-block:: python
  245. TAGGIT_CASE_INSENSITIVE = True
  246. Tags are case-sensitive by default ('music' and 'Music' are treated as distinct tags). In many cases the reverse behaviour is preferable.
  247. Multi-word tags
  248. ---------------
  249. .. code-block:: python
  250. TAG_SPACES_ALLOWED = False
  251. Tags can only consist of a single word, no spaces allowed. The default setting is ``True`` (spaces in tags are allowed).
  252. Tag limit
  253. ---------
  254. .. code-block:: python
  255. TAG_LIMIT = 5
  256. Limit the number of tags that can be added to (django-taggit) Tag model. Default setting is ``None``, meaning no limit on tags.
  257. Unicode Page Slugs
  258. ------------------
  259. .. code-block:: python
  260. WAGTAIL_ALLOW_UNICODE_SLUGS = True
  261. By default, page slugs can contain any alphanumeric characters, including non-Latin alphabets. Set this to False to limit slugs to ASCII characters.
  262. .. _WAGTAIL_AUTO_UPDATE_PREVIEW:
  263. Auto update preview
  264. -------------------
  265. .. code-block:: python
  266. WAGTAIL_AUTO_UPDATE_PREVIEW = False
  267. When enabled, data from an edited page is automatically sent to the server
  268. on each change, even without saving. That way, users don’t have to click on
  269. “Preview” to update the content of the preview page. However, the preview page
  270. tab is not refreshed automatically, users have to do it manually.
  271. This behaviour is disabled by default.
  272. Custom User Edit Forms
  273. ----------------------
  274. See :doc:`/advanced_topics/customisation/custom_user_models`.
  275. .. code-block:: python
  276. WAGTAIL_USER_EDIT_FORM = 'users.forms.CustomUserEditForm'
  277. Allows the default ``UserEditForm`` class to be overridden with a custom form when
  278. a custom user model is being used and extra fields are required in the user edit form.
  279. .. code-block:: python
  280. WAGTAIL_USER_CREATION_FORM = 'users.forms.CustomUserCreationForm'
  281. Allows the default ``UserCreationForm`` class to be overridden with a custom form when
  282. a custom user model is being used and extra fields are required in the user creation form.
  283. .. code-block:: python
  284. WAGTAIL_USER_CUSTOM_FIELDS = ['country']
  285. A list of the extra custom fields to be appended to the default list.
  286. .. _WAGTAIL_USAGE_COUNT_ENABLED:
  287. Usage for images, documents and snippets
  288. ----------------------------------------
  289. .. code-block:: python
  290. WAGTAIL_USAGE_COUNT_ENABLED = True
  291. When enabled Wagtail shows where a particular image, document or snippet is being used on your site.
  292. This is disabled by default because it generates a query which may run slowly on sites with large numbers of pages.
  293. A link will appear on the edit page (in the rightmost column) showing you how many times the item is used.
  294. Clicking this link takes you to the "Usage" page, which shows you where the snippet, document or image is used.
  295. The link is also shown on the delete page, above the "Delete" button.
  296. .. note::
  297. The usage count only applies to direct (database) references. Using documents, images and snippets within StreamFields or rich text fields will not be taken into account.
  298. Date and DateTime inputs
  299. ------------------------
  300. .. code-block:: python
  301. WAGTAIL_DATE_FORMAT = '%d.%m.%Y.'
  302. WAGTAIL_DATETIME_FORMAT = '%d.%m.%Y. %H:%M'
  303. Specifies the date and datetime format to be used in input fields in the Wagtail admin. The format is specified in `Python datetime module syntax <https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior>`_, and must be one of the recognised formats listed in the ``DATE_INPUT_FORMATS`` or ``DATETIME_INPUT_FORMATS`` setting respectively (see `DATE_INPUT_FORMATS <https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DATE_INPUT_FORMATS>`_).
  304. .. _WAGTAIL_USER_TIME_ZONES:
  305. Time zones
  306. ----------
  307. Logged-in users can choose their current time zone for the admin interface in the account settings. If is no time zone selected by the user, then ``TIME_ZONE`` will be used.
  308. (Note that time zones are only applied to datetime fields, not to plain time or date fields. This is a Django design decision.)
  309. The list of time zones is by default the common_timezones list from pytz.
  310. It is possible to override this list via the ``WAGTAIL_USER_TIME_ZONES`` setting.
  311. If there is zero or one time zone permitted, the account settings form will be hidden.
  312. .. code-block:: python
  313. WAGTAIL_USER_TIME_ZONES = ['America/Chicago', 'Australia/Sydney', 'Europe/Rome']
  314. .. _WAGTAILADMIN_PERMITTED_LANGUAGES:
  315. Admin languages
  316. ---------------
  317. Users can choose between several languages for the admin interface
  318. in the account settings. The list of languages is by default all the available
  319. languages in Wagtail with at least 90% coverage. To change it, set ``WAGTAILADMIN_PERMITTED_LANGUAGES``:
  320. .. code-block:: python
  321. WAGTAILADMIN_PERMITTED_LANGUAGES = [('en', 'English'),
  322. ('pt', 'Portuguese')]
  323. Since the syntax is the same as Django ``LANGUAGES``, you can do this so users
  324. can only choose between front office languages:
  325. .. code-block:: python
  326. LANGUAGES = WAGTAILADMIN_PERMITTED_LANGUAGES = [('en', 'English'),
  327. ('pt', 'Portuguese')]
  328. Static files
  329. ------------
  330. .. code-block:: python
  331. WAGTAILADMIN_STATIC_FILE_VERSION_STRINGS = False
  332. Static file URLs within the Wagtail admin are given a version-specific query string of the form ``?v=1a2b3c4d``, to prevent outdated cached copies of Javascript and CSS files from persisting after a Wagtail upgrade. To disable these, set ``WAGTAILADMIN_STATIC_FILE_VERSION_STRINGS`` to ``False``.
  333. API Settings
  334. ------------
  335. For full documenation on API configuration, including these settings, see :ref:`api_v2_configuration` documentation.
  336. .. code-block:: python
  337. WAGTAILAPI_BASE_URL = 'http://api.example.com/'
  338. Required when using frontend cache invalidation, used to generate absolute URLs to document files and invalidating the cache.
  339. .. code-block:: python
  340. WAGTAILAPI_LIMIT_MAX = 500
  341. Default is 20, used to change the maximum number of results a user can request at a time, set to ``None`` for no limit.
  342. .. code-block:: python
  343. WAGTAILAPI_SEARCH_ENABLED = False
  344. Default is true, setting this to false will disable full text search on all endpoints.
  345. .. code-block:: python
  346. WAGTAILAPI_USE_FRONTENDCACHE = True
  347. Requires ``wagtailfrontendcache`` app to be installed, inidicates the API should use the frontend cache.
  348. Frontend cache
  349. --------------
  350. For full documenation on frontend cache invalidation, including these settings, see :ref:`frontend_cache_purging`.
  351. .. code-block:: python
  352. WAGTAILFRONTENDCACHE = {
  353. 'varnish': {
  354. 'BACKEND': 'wagtail.contrib.frontend_cache.backends.HTTPBackend',
  355. 'LOCATION': 'http://localhost:8000',
  356. },
  357. }
  358. See documentation linked above for full options available.
  359. .. note::
  360. ``WAGTAILFRONTENDCACHE_LOCATION`` is no longer the preferred way to set the cache location, instead set the ``LOCATION`` within the ``WAGTAILFRONTENDCACHE`` item.
  361. .. code-block:: python
  362. WAGTAILFRONTENDCACHE_LANGUAGES = [l[0] for l in settings.LANGUAGES]
  363. Default is an empty list, must be a list of languages to also purge the urls for each language of a purging url. This setting needs ``settings.USE_I18N`` to be ``True`` to work.
  364. .. _WAGTAILADMIN_RICH_TEXT_EDITORS:
  365. Rich text
  366. ---------
  367. .. code-block:: python
  368. WAGTAILADMIN_RICH_TEXT_EDITORS = {
  369. 'default': {
  370. 'WIDGET': 'wagtail.admin.rich_text.DraftailRichTextArea',
  371. 'OPTIONS': {
  372. 'features': ['h2', 'bold', 'italic', 'link', 'document-link']
  373. }
  374. },
  375. 'legacy': {
  376. 'WIDGET': 'wagtail.admin.rich_text.HalloRichTextArea',
  377. }
  378. }
  379. Customise the behaviour of rich text fields. By default, ``RichTextField`` and ``RichTextBlock`` use the configuration given under the ``'default'`` key, but this can be overridden on a per-field basis through the ``editor`` keyword argument, e.g. ``body = RichTextField(editor='legacy')``. Within each configuration block, the following fields are recognised:
  380. * ``WIDGET``: The rich text widget implementation to use. Wagtail provides two implementations: ``wagtail.admin.rich_text.DraftailRichTextArea`` (a modern extensible editor which enforces well-structured markup) and ``wagtail.admin.rich_text.HalloRichTextArea`` (deprecated; works directly at the HTML level). Other widgets may be provided by third-party packages.
  381. * ``OPTIONS``: Configuration options to pass to the widget. Recognised options are widget-specific, but both ``DraftailRichTextArea`` and ``HalloRichTextArea`` accept a ``features`` list indicating the active rich text features (see :ref:`rich_text_features`).
  382. URL Patterns
  383. ~~~~~~~~~~~~
  384. .. code-block:: python
  385. from django.contrib import admin
  386. from wagtail.core import urls as wagtail_urls
  387. from wagtail.admin import urls as wagtailadmin_urls
  388. from wagtail.documents import urls as wagtaildocs_urls
  389. urlpatterns = [
  390. re_path(r'^django-admin/', include(admin.site.urls)),
  391. re_path(r'^admin/', include(wagtailadmin_urls)),
  392. re_path(r'^documents/', include(wagtaildocs_urls)),
  393. # Optional URL for including your own vanilla Django urls/views
  394. re_path(r'', include('myapp.urls')),
  395. # For anything not caught by a more specific rule above, hand over to
  396. # Wagtail's serving mechanism
  397. re_path(r'', include(wagtail_urls)),
  398. ]
  399. This block of code for your project's ``urls.py`` does a few things:
  400. * Load the vanilla Django admin interface to ``/django-admin/``
  401. * Load the Wagtail admin and its various apps
  402. * Dispatch any vanilla Django apps you're using other than Wagtail which require their own URL configuration (this is optional, since Wagtail might be all you need)
  403. * Lets Wagtail handle any further URL dispatching.
  404. That's not everything you might want to include in your project's URL configuration, but it's what's necessary for Wagtail to flourish.
  405. .. _complete_example_config:
  406. Ready to Use Example Configuration Files
  407. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  408. These two files should reside in your project directory (``myproject/myproject/``).
  409. ``settings.py``
  410. ---------------
  411. .. code-block:: python
  412. import os
  413. PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  414. BASE_DIR = os.path.dirname(PROJECT_DIR)
  415. DEBUG = True
  416. # Application definition
  417. INSTALLED_APPS = [
  418. 'myapp',
  419. 'wagtail.contrib.forms',
  420. 'wagtail.contrib.redirects',
  421. 'wagtail.embeds',
  422. 'wagtail.sites',
  423. 'wagtail.users',
  424. 'wagtail.snippets',
  425. 'wagtail.documents',
  426. 'wagtail.images',
  427. 'wagtail.search',
  428. 'wagtail.admin',
  429. 'wagtail.core',
  430. 'taggit',
  431. 'modelcluster',
  432. 'django.contrib.auth',
  433. 'django.contrib.contenttypes',
  434. 'django.contrib.sessions',
  435. 'django.contrib.messages',
  436. 'django.contrib.staticfiles',
  437. ]
  438. MIDDLEWARE = [
  439. 'django.contrib.sessions.middleware.SessionMiddleware',
  440. 'django.middleware.common.CommonMiddleware',
  441. 'django.middleware.csrf.CsrfViewMiddleware',
  442. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  443. 'django.contrib.messages.middleware.MessageMiddleware',
  444. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  445. 'django.middleware.security.SecurityMiddleware',
  446. 'wagtail.core.middleware.SiteMiddleware',
  447. 'wagtail.contrib.redirects.middleware.RedirectMiddleware',
  448. ]
  449. ROOT_URLCONF = 'myproject.urls'
  450. TEMPLATES = [
  451. {
  452. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  453. 'DIRS': [
  454. os.path.join(PROJECT_DIR, 'templates'),
  455. ],
  456. 'APP_DIRS': True,
  457. 'OPTIONS': {
  458. 'context_processors': [
  459. 'django.template.context_processors.debug',
  460. 'django.template.context_processors.request',
  461. 'django.contrib.auth.context_processors.auth',
  462. 'django.contrib.messages.context_processors.messages',
  463. ],
  464. },
  465. },
  466. ]
  467. WSGI_APPLICATION = 'myproject.wsgi.application'
  468. # Database
  469. DATABASES = {
  470. 'default': {
  471. 'ENGINE': 'django.db.backends.postgresql',
  472. 'NAME': 'myprojectdb',
  473. 'USER': 'postgres',
  474. 'PASSWORD': '',
  475. 'HOST': '', # Set to empty string for localhost.
  476. 'PORT': '', # Set to empty string for default.
  477. 'CONN_MAX_AGE': 600, # number of seconds database connections should persist for
  478. }
  479. }
  480. # Internationalization
  481. LANGUAGE_CODE = 'en-us'
  482. TIME_ZONE = 'UTC'
  483. USE_I18N = True
  484. USE_L10N = True
  485. USE_TZ = True
  486. # Static files (CSS, JavaScript, Images)
  487. STATICFILES_FINDERS = [
  488. 'django.contrib.staticfiles.finders.FileSystemFinder',
  489. 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
  490. ]
  491. STATICFILES_DIRS = [
  492. os.path.join(PROJECT_DIR, 'static'),
  493. ]
  494. STATIC_ROOT = os.path.join(BASE_DIR, 'static')
  495. STATIC_URL = '/static/'
  496. MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
  497. MEDIA_URL = '/media/'
  498. ADMINS = [
  499. # ('Your Name', 'your_email@example.com'),
  500. ]
  501. MANAGERS = ADMINS
  502. # Default to dummy email backend. Configure dev/production/local backend
  503. # as per https://docs.djangoproject.com/en/dev/topics/email/#email-backends
  504. EMAIL_BACKEND = 'django.core.mail.backends.dummy.EmailBackend'
  505. # Hosts/domain names that are valid for this site; required if DEBUG is False
  506. ALLOWED_HOSTS = []
  507. # Make this unique, and don't share it with anybody.
  508. SECRET_KEY = 'change-me'
  509. EMAIL_SUBJECT_PREFIX = '[Wagtail] '
  510. INTERNAL_IPS = ('127.0.0.1', '10.0.2.2')
  511. # A sample logging configuration. The only tangible logging
  512. # performed by this configuration is to send an email to
  513. # the site admins on every HTTP 500 error when DEBUG=False.
  514. # See https://docs.djangoproject.com/en/dev/topics/logging for
  515. # more details on how to customize your logging configuration.
  516. LOGGING = {
  517. 'version': 1,
  518. 'disable_existing_loggers': False,
  519. 'filters': {
  520. 'require_debug_false': {
  521. '()': 'django.utils.log.RequireDebugFalse'
  522. }
  523. },
  524. 'handlers': {
  525. 'mail_admins': {
  526. 'level': 'ERROR',
  527. 'filters': ['require_debug_false'],
  528. 'class': 'django.utils.log.AdminEmailHandler'
  529. }
  530. },
  531. 'loggers': {
  532. 'django.request': {
  533. 'handlers': ['mail_admins'],
  534. 'level': 'ERROR',
  535. 'propagate': True,
  536. },
  537. }
  538. }
  539. # WAGTAIL SETTINGS
  540. # This is the human-readable name of your Wagtail install
  541. # which welcomes users upon login to the Wagtail admin.
  542. WAGTAIL_SITE_NAME = 'My Project'
  543. # Override the search results template for wagtailsearch
  544. # WAGTAILSEARCH_RESULTS_TEMPLATE = 'myapp/search_results.html'
  545. # WAGTAILSEARCH_RESULTS_TEMPLATE_AJAX = 'myapp/includes/search_listing.html'
  546. # Replace the search backend
  547. #WAGTAILSEARCH_BACKENDS = {
  548. # 'default': {
  549. # 'BACKEND': 'wagtail.search.backends.elasticsearch2',
  550. # 'INDEX': 'myapp'
  551. # }
  552. #}
  553. # Wagtail email notifications from address
  554. # WAGTAILADMIN_NOTIFICATION_FROM_EMAIL = 'wagtail@myhost.io'
  555. # Wagtail email notification format
  556. # WAGTAILADMIN_NOTIFICATION_USE_HTML = True
  557. # Reverse the default case-sensitive handling of tags
  558. TAGGIT_CASE_INSENSITIVE = True
  559. ``urls.py``
  560. -----------
  561. .. code-block:: python
  562. from django.conf.urls import include, re_path
  563. from django.conf.urls.static import static
  564. from django.views.generic.base import RedirectView
  565. from django.contrib import admin
  566. from django.conf import settings
  567. import os.path
  568. from wagtail.core import urls as wagtail_urls
  569. from wagtail.admin import urls as wagtailadmin_urls
  570. from wagtail.documents import urls as wagtaildocs_urls
  571. urlpatterns = [
  572. re_path(r'^django-admin/', include(admin.site.urls)),
  573. re_path(r'^admin/', include(wagtailadmin_urls)),
  574. re_path(r'^documents/', include(wagtaildocs_urls)),
  575. # For anything not caught by a more specific rule above, hand over to
  576. # Wagtail's serving mechanism
  577. re_path(r'', include(wagtail_urls)),
  578. ]
  579. if settings.DEBUG:
  580. from django.contrib.staticfiles.urls import staticfiles_urlpatterns
  581. urlpatterns += staticfiles_urlpatterns() # tell gunicorn where static files are in dev mode
  582. urlpatterns += static(settings.MEDIA_URL + 'images/', document_root=os.path.join(settings.MEDIA_ROOT, 'images'))
  583. urlpatterns += [
  584. re_path(r'^favicon\.ico$', RedirectView.as_view(url=settings.STATIC_URL + 'myapp/images/favicon.ico'))
  585. ]