settings.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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 `Writing your first Django app <https://docs.djangoproject.com/en/dev/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 `Django Settings <https://docs.djangoproject.com/en/dev/topics/settings/>`__ and `Django URL Dispatcher <https://docs.djangoproject.com/en/dev/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_CLASSES = (
  24. 'django.middleware.common.CommonMiddleware',
  25. 'django.contrib.sessions.middleware.SessionMiddleware',
  26. 'django.middleware.csrf.CsrfViewMiddleware',
  27. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  28. 'django.contrib.messages.middleware.MessageMiddleware',
  29. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  30. 'wagtail.wagtailcore.middleware.SiteMiddleware',
  31. 'wagtail.wagtailredirects.middleware.RedirectMiddleware',
  32. )
  33. Wagtail requires several common Django middleware modules to work and cover basic security. Wagtail provides its own middleware to cover these tasks:
  34. ``SiteMiddleware``
  35. Wagtail routes pre-defined hosts to pages within the Wagtail tree using this middleware.
  36. ``RedirectMiddleware``
  37. Wagtail provides a simple interface for adding arbitrary redirects to your site and this module makes it happen.
  38. Apps (``settings.py``)
  39. ~~~~~~~~~~~~~~~~~~~~~~
  40. .. code-block:: python
  41. INSTALLED_APPS = (
  42. 'django.contrib.auth',
  43. 'django.contrib.contenttypes',
  44. 'django.contrib.sessions',
  45. 'django.contrib.messages',
  46. 'django.contrib.staticfiles',
  47. 'compressor',
  48. 'taggit',
  49. 'modelcluster',
  50. 'wagtail.wagtailcore',
  51. 'wagtail.wagtailadmin',
  52. 'wagtail.wagtaildocs',
  53. 'wagtail.wagtailsnippets',
  54. 'wagtail.wagtailusers',
  55. 'wagtail.wagtailimages',
  56. 'wagtail.wagtailembeds',
  57. 'wagtail.wagtailsearch',
  58. 'wagtail.wagtailsites',
  59. 'wagtail.wagtailredirects',
  60. 'wagtail.wagtailforms',
  61. 'myapp', # your own app
  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. Third-Party Apps
  65. ----------------
  66. ``compressor``
  67. Static asset combiner and minifier for Django. Compressor also enables for the use of preprocessors. See `Compressor Documentation`_.
  68. .. _Compressor Documentation: http://django-compressor.readthedocs.org/en/latest/
  69. ``taggit``
  70. 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`_.
  71. .. _Taggit Documentation: http://django-taggit.readthedocs.org/en/latest/index.html
  72. ``modelcluster``
  73. 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`_.
  74. .. _the django-modelcluster github project page: https://github.com/torchbox/django-modelcluster
  75. Wagtail Apps
  76. ------------
  77. ``wagtailcore``
  78. The core functionality of Wagtail, such as the ``Page`` class, the Wagtail tree, and model fields.
  79. ``wagtailadmin``
  80. The administration interface for Wagtail, including page edit handlers.
  81. ``wagtaildocs``
  82. The Wagtail document content type.
  83. ``wagtailsnippets``
  84. Editing interface for non-Page models and objects. See :ref:`Snippets`.
  85. ``wagtailusers``
  86. User editing interface.
  87. ``wagtailimages``
  88. The Wagtail image content type.
  89. ``wagtailembeds``
  90. Module governing oEmbed and Embedly content in Wagtail rich text fields. See :ref:`inserting_videos`.
  91. ``wagtailsearch``
  92. Search framework for Page content. See :ref:`search`.
  93. ``wagtailredirects``
  94. Admin interface for creating arbitrary redirects on your site.
  95. ``wagtailforms``
  96. Models for creating forms on your pages and viewing submissions. See :ref:`form_builder`.
  97. Settings Variables (``settings.py``)
  98. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  99. Site Name
  100. ---------
  101. .. code-block:: python
  102. WAGTAIL_SITE_NAME = 'Stark Industries Skunkworks'
  103. This is the human-readable name of your Wagtail install which welcomes users upon login to the Wagtail admin.
  104. Search
  105. ------
  106. .. code-block:: python
  107. # Override the search results template for wagtailsearch
  108. WAGTAILSEARCH_RESULTS_TEMPLATE = 'myapp/search_results.html'
  109. WAGTAILSEARCH_RESULTS_TEMPLATE_AJAX = 'myapp/includes/search_listing.html'
  110. # Replace the search backend
  111. WAGTAILSEARCH_BACKENDS = {
  112. 'default': {
  113. 'BACKEND': 'wagtail.wagtailsearch.backends.elasticsearch',
  114. 'INDEX': 'myapp'
  115. }
  116. }
  117. The search settings customise the search results templates as well as choosing a custom backend for search. For a full explanation, see :ref:`search`.
  118. Embeds
  119. ------
  120. Wagtail uses the oEmbed standard with a large but not comprehensive number of "providers" (Youtube, Vimeo, etc.). You can also use a different embed backend by providing an Embedly key or replacing the embed backend by writing your own embed finder function.
  121. .. code-block:: python
  122. WAGTAILEMBEDS_EMBED_FINDER = 'myapp.embeds.my_embed_finder_function'
  123. Use a custom embed finder function, which takes a URL and returns a dict with metadata and embeddable HTML. Refer to the ``wagtail.wagtailemebds.embeds`` module source for more information and examples.
  124. .. code-block:: python
  125. # not a working key, get your own!
  126. WAGTAILEMBEDS_EMBEDLY_KEY = '253e433d59dc4d2xa266e9e0de0cb830'
  127. Providing an API key for the Embedly service will use that as a embed backend, with a more extensive list of providers, as well as analytics and other features. For more information, see `Embedly`_.
  128. .. _Embedly: http://embed.ly/
  129. To use Embedly, you must also install their Python module:
  130. .. code-block:: sh
  131. pip install embedly
  132. Images
  133. ------
  134. .. code-block:: python
  135. WAGTAILIMAGES_IMAGE_MODEL = 'myapp.MyImage'
  136. 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.
  137. Email Notifications
  138. -------------------
  139. .. code-block:: python
  140. WAGTAILADMIN_NOTIFICATION_FROM_EMAIL = 'wagtail@myhost.io'
  141. 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.
  142. .. _update_notifications:
  143. Wagtail update notifications
  144. ----------------------------
  145. .. code-block:: python
  146. WAGTAIL_ENABLE_UPDATE_CHECK = True
  147. 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.
  148. Private Pages
  149. -------------
  150. .. code-block:: python
  151. PASSWORD_REQUIRED_TEMPLATE = 'myapp/password_required.html'
  152. 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.
  153. Other Django Settings Used by Wagtail
  154. -------------------------------------
  155. .. code-block:: python
  156. ALLOWED_HOSTS
  157. APPEND_SLASH
  158. AUTH_USER_MODEL
  159. BASE_URL
  160. CACHES
  161. DEFAULT_FROM_EMAIL
  162. INSTALLED_APPS
  163. MEDIA_ROOT
  164. SESSION_COOKIE_DOMAIN
  165. SESSION_COOKIE_NAME
  166. SESSION_COOKIE_PATH
  167. STATIC_URL
  168. TEMPLATE_CONTEXT_PROCESSORS
  169. USE_I18N
  170. For information on what these settings do, see `Django Settings <https://docs.djangoproject.com/en/dev/ref/settings/>`__.
  171. URL Patterns
  172. ------------
  173. .. code-block:: python
  174. from django.contrib import admin
  175. from wagtail.wagtailcore import urls as wagtail_urls
  176. from wagtail.wagtailadmin import urls as wagtailadmin_urls
  177. from wagtail.wagtaildocs import urls as wagtaildocs_urls
  178. from wagtail.wagtailsearch import urls as wagtailsearch_urls
  179. urlpatterns = [
  180. url(r'^django-admin/', include(admin.site.urls)),
  181. url(r'^admin/', include(wagtailadmin_urls)),
  182. url(r'^search/', include(wagtailsearch_urls)),
  183. url(r'^documents/', include(wagtaildocs_urls)),
  184. # Optional URL for including your own vanilla Django urls/views
  185. url(r'', include('myapp.urls')),
  186. # For anything not caught by a more specific rule above, hand over to
  187. # Wagtail's serving mechanism
  188. url(r'', include(wagtail_urls)),
  189. ]
  190. This block of code for your project's ``urls.py`` does a few things:
  191. * Load the vanilla Django admin interface to ``/django-admin/``
  192. * Load the Wagtail admin and its various apps
  193. * 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)
  194. * Lets Wagtail handle any further URL dispatching.
  195. 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.
  196. .. _complete_example_config:
  197. Ready to Use Example Configuration Files
  198. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  199. These two files should reside in your project directory (``myproject/myproject/``).
  200. ``settings.py``
  201. ---------------
  202. .. code-block:: python
  203. import os
  204. PROJECT_ROOT = os.path.join(os.path.dirname(__file__), '..', '..')
  205. DEBUG = True
  206. TEMPLATE_DEBUG = DEBUG
  207. ADMINS = (
  208. # ('Your Name', 'your_email@example.com'),
  209. )
  210. MANAGERS = ADMINS
  211. # Default to dummy email backend. Configure dev/production/local backend
  212. # as per https://docs.djangoproject.com/en/dev/topics/email/#email-backends
  213. EMAIL_BACKEND = 'django.core.mail.backends.dummy.EmailBackend'
  214. DATABASES = {
  215. 'default': {
  216. 'ENGINE': 'django.db.backends.postgresql_psycopg2',
  217. 'NAME': 'myprojectdb',
  218. 'USER': 'postgres',
  219. 'PASSWORD': '',
  220. 'HOST': '', # Set to empty string for localhost.
  221. 'PORT': '', # Set to empty string for default.
  222. 'CONN_MAX_AGE': 600, # number of seconds database connections should persist for
  223. }
  224. }
  225. # Hosts/domain names that are valid for this site; required if DEBUG is False
  226. # See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
  227. ALLOWED_HOSTS = []
  228. # Local time zone for this installation. Choices can be found here:
  229. # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
  230. # although not all choices may be available on all operating systems.
  231. # On Unix systems, a value of None will cause Django to use the same
  232. # timezone as the operating system.
  233. # If running in a Windows environment this must be set to the same as your
  234. # system time zone.
  235. TIME_ZONE = 'Europe/London'
  236. # Language code for this installation. All choices can be found here:
  237. # http://www.i18nguy.com/unicode/language-identifiers.html
  238. LANGUAGE_CODE = 'en-gb'
  239. SITE_ID = 1
  240. # If you set this to False, Django will make some optimizations so as not
  241. # to load the internationalization machinery.
  242. USE_I18N = True
  243. # If you set this to False, Django will not format dates, numbers and
  244. # calendars according to the current locale.
  245. # Note that with this set to True, Wagtail will fall back on using numeric dates
  246. # in date fields, as opposed to 'friendly' dates like "24 Sep 2013", because
  247. # Python's strptime doesn't support localised month names: https://code.djangoproject.com/ticket/13339
  248. USE_L10N = False
  249. # If you set this to False, Django will not use timezone-aware datetimes.
  250. USE_TZ = True
  251. # Absolute filesystem path to the directory that will hold user-uploaded files.
  252. # Example: "/home/media/media.lawrence.com/media/"
  253. MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media')
  254. # URL that handles the media served from MEDIA_ROOT. Make sure to use a
  255. # trailing slash.
  256. # Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
  257. MEDIA_URL = '/media/'
  258. # Absolute path to the directory static files should be collected to.
  259. # Don't put anything in this directory yourself; store your static files
  260. # in apps' "static/" subdirectories and in STATICFILES_DIRS.
  261. # Example: "/home/media/media.lawrence.com/static/"
  262. STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
  263. # URL prefix for static files.
  264. # Example: "http://media.lawrence.com/static/"
  265. STATIC_URL = '/static/'
  266. # List of finder classes that know how to find static files in
  267. # various locations.
  268. STATICFILES_FINDERS = (
  269. 'django.contrib.staticfiles.finders.FileSystemFinder',
  270. 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
  271. 'compressor.finders.CompressorFinder',
  272. )
  273. # Make this unique, and don't share it with anybody.
  274. SECRET_KEY = 'change-me'
  275. # List of callables that know how to import templates from various sources.
  276. TEMPLATE_LOADERS = (
  277. 'django.template.loaders.filesystem.Loader',
  278. 'django.template.loaders.app_directories.Loader',
  279. )
  280. MIDDLEWARE_CLASSES = (
  281. 'django.middleware.common.CommonMiddleware',
  282. 'django.contrib.sessions.middleware.SessionMiddleware',
  283. 'django.middleware.csrf.CsrfViewMiddleware',
  284. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  285. 'django.contrib.messages.middleware.MessageMiddleware',
  286. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  287. 'wagtail.wagtailcore.middleware.SiteMiddleware',
  288. 'wagtail.wagtailredirects.middleware.RedirectMiddleware',
  289. )
  290. from django.conf import global_settings
  291. TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
  292. 'django.core.context_processors.request',
  293. )
  294. ROOT_URLCONF = 'myproject.urls'
  295. # Python dotted path to the WSGI application used by Django's runserver.
  296. WSGI_APPLICATION = 'wagtaildemo.wsgi.application'
  297. INSTALLED_APPS = (
  298. 'django.contrib.auth',
  299. 'django.contrib.contenttypes',
  300. 'django.contrib.sessions',
  301. 'django.contrib.messages',
  302. 'django.contrib.staticfiles',
  303. 'compressor',
  304. 'taggit',
  305. 'modelcluster',
  306. 'wagtail.wagtailcore',
  307. 'wagtail.wagtailadmin',
  308. 'wagtail.wagtaildocs',
  309. 'wagtail.wagtailsnippets',
  310. 'wagtail.wagtailusers',
  311. 'wagtail.wagtailimages',
  312. 'wagtail.wagtailembeds',
  313. 'wagtail.wagtailsearch',
  314. 'wagtail.wagtailredirects',
  315. 'wagtail.wagtailforms',
  316. 'myapp',
  317. )
  318. EMAIL_SUBJECT_PREFIX = '[Wagtail] '
  319. INTERNAL_IPS = ('127.0.0.1', '10.0.2.2')
  320. # A sample logging configuration. The only tangible logging
  321. # performed by this configuration is to send an email to
  322. # the site admins on every HTTP 500 error when DEBUG=False.
  323. # See http://docs.djangoproject.com/en/dev/topics/logging for
  324. # more details on how to customize your logging configuration.
  325. LOGGING = {
  326. 'version': 1,
  327. 'disable_existing_loggers': False,
  328. 'filters': {
  329. 'require_debug_false': {
  330. '()': 'django.utils.log.RequireDebugFalse'
  331. }
  332. },
  333. 'handlers': {
  334. 'mail_admins': {
  335. 'level': 'ERROR',
  336. 'filters': ['require_debug_false'],
  337. 'class': 'django.utils.log.AdminEmailHandler'
  338. }
  339. },
  340. 'loggers': {
  341. 'django.request': {
  342. 'handlers': ['mail_admins'],
  343. 'level': 'ERROR',
  344. 'propagate': True,
  345. },
  346. }
  347. }
  348. # WAGTAIL SETTINGS
  349. # This is the human-readable name of your Wagtail install
  350. # which welcomes users upon login to the Wagtail admin.
  351. WAGTAIL_SITE_NAME = 'My Project'
  352. # Override the search results template for wagtailsearch
  353. # WAGTAILSEARCH_RESULTS_TEMPLATE = 'myapp/search_results.html'
  354. # WAGTAILSEARCH_RESULTS_TEMPLATE_AJAX = 'myapp/includes/search_listing.html'
  355. # Replace the search backend
  356. #WAGTAILSEARCH_BACKENDS = {
  357. # 'default': {
  358. # 'BACKEND': 'wagtail.wagtailsearch.backends.elasticsearch',
  359. # 'INDEX': 'myapp'
  360. # }
  361. #}
  362. # Wagtail email notifications from address
  363. # WAGTAILADMIN_NOTIFICATION_FROM_EMAIL = 'wagtail@myhost.io'
  364. # If you want to use Embedly for embeds, supply a key
  365. # (this key doesn't work, get your own!)
  366. # WAGTAILEMBEDS_EMBEDLY_KEY = '253e433d59dc4d2xa266e9e0de0cb830'
  367. ``urls.py``
  368. -----------
  369. .. code-block:: python
  370. from django.conf.urls import patterns, include, url
  371. from django.conf.urls.static import static
  372. from django.views.generic.base import RedirectView
  373. from django.contrib import admin
  374. from django.conf import settings
  375. import os.path
  376. from wagtail.wagtailcore import urls as wagtail_urls
  377. from wagtail.wagtailadmin import urls as wagtailadmin_urls
  378. from wagtail.wagtaildocs import urls as wagtaildocs_urls
  379. from wagtail.wagtailsearch import urls as wagtailsearch__urls
  380. urlpatterns = patterns('',
  381. url(r'^django-admin/', include(admin.site.urls)),
  382. url(r'^admin/', include(wagtailadmin_urls)),
  383. url(r'^search/', include(wagtailsearch_urls)),
  384. url(r'^documents/', include(wagtaildocs_urls)),
  385. # For anything not caught by a more specific rule above, hand over to
  386. # Wagtail's serving mechanism
  387. url(r'', include(wagtail_urls)),
  388. )
  389. if settings.DEBUG:
  390. from django.contrib.staticfiles.urls import staticfiles_urlpatterns
  391. urlpatterns += staticfiles_urlpatterns() # tell gunicorn where static files are in dev mode
  392. urlpatterns += static(settings.MEDIA_URL + 'images/', document_root=os.path.join(settings.MEDIA_ROOT, 'images'))
  393. urlpatterns += patterns('',
  394. (r'^favicon\.ico$', RedirectView.as_view(url=settings.STATIC_URL + 'myapp/images/favicon.ico'))
  395. )