settings.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  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 urlconfs 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. For configuring sites, see :ref:`wagtail_site_admin`.
  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.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. 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:: bash
  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. Private Pages
  143. -------------
  144. .. code-block:: python
  145. PASSWORD_REQUIRED_TEMPLATE = 'myapp/password_required.html'
  146. 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.
  147. Other Django Settings Used by Wagtail
  148. -------------------------------------
  149. .. code-block:: python
  150. ALLOWED_HOSTS
  151. APPEND_SLASH
  152. AUTH_USER_MODEL
  153. BASE_URL
  154. CACHES
  155. DEFAULT_FROM_EMAIL
  156. INSTALLED_APPS
  157. MEDIA_ROOT
  158. SESSION_COOKIE_DOMAIN
  159. SESSION_COOKIE_NAME
  160. SESSION_COOKIE_PATH
  161. STATIC_URL
  162. TEMPLATE_CONTEXT_PROCESSORS
  163. USE_I18N
  164. For information on what these settings do, see `Django Settings <https://docs.djangoproject.com/en/dev/ref/settings/>`__.
  165. URL Patterns
  166. ------------
  167. .. code-block:: python
  168. from django.contrib import admin
  169. from wagtail.wagtailcore import urls as wagtail_urls
  170. from wagtail.wagtailadmin import urls as wagtailadmin_urls
  171. from wagtail.wagtaildocs import urls as wagtaildocs_urls
  172. from wagtail.wagtailsearch import urls as wagtailsearch_urls
  173. urlpatterns = [
  174. url(r'^django-admin/', include(admin.site.urls)),
  175. url(r'^admin/', include(wagtailadmin_urls)),
  176. url(r'^search/', include(wagtailsearch_urls)),
  177. url(r'^documents/', include(wagtaildocs_urls)),
  178. # Optional urlconf for including your own vanilla Django urls/views
  179. url(r'', include('myapp.urls')),
  180. # For anything not caught by a more specific rule above, hand over to
  181. # Wagtail's serving mechanism
  182. url(r'', include(wagtail_urls)),
  183. ]
  184. This block of code for your project's ``urls.py`` does a few things:
  185. * Load the vanilla Django admin interface to ``/django-admin/``
  186. * Load the Wagtail admin and its various apps
  187. * Dispatch any vanilla Django apps you're using other than Wagtail which require their own urlconfs (this is optional, since Wagtail might be all you need)
  188. * Lets Wagtail handle any further URL dispatching.
  189. That's not everything you might want to include in your project's urlconf, but it's what's necessary for Wagtail to flourish.
  190. .. _complete_example_config:
  191. Ready to Use Example Configuration Files
  192. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  193. These two files should reside in your project directory (``myproject/myproject/``).
  194. ``settings.py``
  195. ---------------
  196. .. code-block:: python
  197. import os
  198. PROJECT_ROOT = os.path.join(os.path.dirname(__file__), '..', '..')
  199. DEBUG = True
  200. TEMPLATE_DEBUG = DEBUG
  201. ADMINS = (
  202. # ('Your Name', 'your_email@example.com'),
  203. )
  204. MANAGERS = ADMINS
  205. # Default to dummy email backend. Configure dev/production/local backend
  206. # as per https://docs.djangoproject.com/en/dev/topics/email/#email-backends
  207. EMAIL_BACKEND = 'django.core.mail.backends.dummy.EmailBackend'
  208. DATABASES = {
  209. 'default': {
  210. 'ENGINE': 'django.db.backends.postgresql_psycopg2',
  211. 'NAME': 'myprojectdb',
  212. 'USER': 'postgres',
  213. 'PASSWORD': '',
  214. 'HOST': '', # Set to empty string for localhost.
  215. 'PORT': '', # Set to empty string for default.
  216. 'CONN_MAX_AGE': 600, # number of seconds database connections should persist for
  217. }
  218. }
  219. # Hosts/domain names that are valid for this site; required if DEBUG is False
  220. # See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
  221. ALLOWED_HOSTS = []
  222. # Local time zone for this installation. Choices can be found here:
  223. # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
  224. # although not all choices may be available on all operating systems.
  225. # On Unix systems, a value of None will cause Django to use the same
  226. # timezone as the operating system.
  227. # If running in a Windows environment this must be set to the same as your
  228. # system time zone.
  229. TIME_ZONE = 'Europe/London'
  230. # Language code for this installation. All choices can be found here:
  231. # http://www.i18nguy.com/unicode/language-identifiers.html
  232. LANGUAGE_CODE = 'en-gb'
  233. SITE_ID = 1
  234. # If you set this to False, Django will make some optimizations so as not
  235. # to load the internationalization machinery.
  236. USE_I18N = True
  237. # If you set this to False, Django will not format dates, numbers and
  238. # calendars according to the current locale.
  239. # Note that with this set to True, Wagtail will fall back on using numeric dates
  240. # in date fields, as opposed to 'friendly' dates like "24 Sep 2013", because
  241. # Python's strptime doesn't support localised month names: https://code.djangoproject.com/ticket/13339
  242. USE_L10N = False
  243. # If you set this to False, Django will not use timezone-aware datetimes.
  244. USE_TZ = True
  245. # Absolute filesystem path to the directory that will hold user-uploaded files.
  246. # Example: "/home/media/media.lawrence.com/media/"
  247. MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media')
  248. # URL that handles the media served from MEDIA_ROOT. Make sure to use a
  249. # trailing slash.
  250. # Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
  251. MEDIA_URL = '/media/'
  252. # Absolute path to the directory static files should be collected to.
  253. # Don't put anything in this directory yourself; store your static files
  254. # in apps' "static/" subdirectories and in STATICFILES_DIRS.
  255. # Example: "/home/media/media.lawrence.com/static/"
  256. STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
  257. # URL prefix for static files.
  258. # Example: "http://media.lawrence.com/static/"
  259. STATIC_URL = '/static/'
  260. # List of finder classes that know how to find static files in
  261. # various locations.
  262. STATICFILES_FINDERS = (
  263. 'django.contrib.staticfiles.finders.FileSystemFinder',
  264. 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
  265. 'compressor.finders.CompressorFinder',
  266. )
  267. # Make this unique, and don't share it with anybody.
  268. SECRET_KEY = 'change-me'
  269. # List of callables that know how to import templates from various sources.
  270. TEMPLATE_LOADERS = (
  271. 'django.template.loaders.filesystem.Loader',
  272. 'django.template.loaders.app_directories.Loader',
  273. )
  274. MIDDLEWARE_CLASSES = (
  275. 'django.middleware.common.CommonMiddleware',
  276. 'django.contrib.sessions.middleware.SessionMiddleware',
  277. 'django.middleware.csrf.CsrfViewMiddleware',
  278. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  279. 'django.contrib.messages.middleware.MessageMiddleware',
  280. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  281. 'wagtail.wagtailcore.middleware.SiteMiddleware',
  282. 'wagtail.wagtailredirects.middleware.RedirectMiddleware',
  283. )
  284. from django.conf import global_settings
  285. TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
  286. 'django.core.context_processors.request',
  287. )
  288. ROOT_URLCONF = 'myproject.urls'
  289. # Python dotted path to the WSGI application used by Django's runserver.
  290. WSGI_APPLICATION = 'wagtaildemo.wsgi.application'
  291. INSTALLED_APPS = (
  292. 'django.contrib.auth',
  293. 'django.contrib.contenttypes',
  294. 'django.contrib.sessions',
  295. 'django.contrib.messages',
  296. 'django.contrib.staticfiles',
  297. 'compressor',
  298. 'taggit',
  299. 'modelcluster',
  300. 'wagtail.wagtailcore',
  301. 'wagtail.wagtailadmin',
  302. 'wagtail.wagtaildocs',
  303. 'wagtail.wagtailsnippets',
  304. 'wagtail.wagtailusers',
  305. 'wagtail.wagtailimages',
  306. 'wagtail.wagtailembeds',
  307. 'wagtail.wagtailsearch',
  308. 'wagtail.wagtailredirects',
  309. 'wagtail.wagtailforms',
  310. 'myapp',
  311. )
  312. EMAIL_SUBJECT_PREFIX = '[Wagtail] '
  313. INTERNAL_IPS = ('127.0.0.1', '10.0.2.2')
  314. # A sample logging configuration. The only tangible logging
  315. # performed by this configuration is to send an email to
  316. # the site admins on every HTTP 500 error when DEBUG=False.
  317. # See http://docs.djangoproject.com/en/dev/topics/logging for
  318. # more details on how to customize your logging configuration.
  319. LOGGING = {
  320. 'version': 1,
  321. 'disable_existing_loggers': False,
  322. 'filters': {
  323. 'require_debug_false': {
  324. '()': 'django.utils.log.RequireDebugFalse'
  325. }
  326. },
  327. 'handlers': {
  328. 'mail_admins': {
  329. 'level': 'ERROR',
  330. 'filters': ['require_debug_false'],
  331. 'class': 'django.utils.log.AdminEmailHandler'
  332. }
  333. },
  334. 'loggers': {
  335. 'django.request': {
  336. 'handlers': ['mail_admins'],
  337. 'level': 'ERROR',
  338. 'propagate': True,
  339. },
  340. }
  341. }
  342. # WAGTAIL SETTINGS
  343. # This is the human-readable name of your Wagtail install
  344. # which welcomes users upon login to the Wagtail admin.
  345. WAGTAIL_SITE_NAME = 'My Project'
  346. # Override the search results template for wagtailsearch
  347. # WAGTAILSEARCH_RESULTS_TEMPLATE = 'myapp/search_results.html'
  348. # WAGTAILSEARCH_RESULTS_TEMPLATE_AJAX = 'myapp/includes/search_listing.html'
  349. # Replace the search backend
  350. #WAGTAILSEARCH_BACKENDS = {
  351. # 'default': {
  352. # 'BACKEND': 'wagtail.wagtailsearch.backends.elasticsearch.ElasticSearch',
  353. # 'INDEX': 'myapp'
  354. # }
  355. #}
  356. # Wagtail email notifications from address
  357. # WAGTAILADMIN_NOTIFICATION_FROM_EMAIL = 'wagtail@myhost.io'
  358. # If you want to use Embedly for embeds, supply a key
  359. # (this key doesn't work, get your own!)
  360. # EMBEDLY_KEY = '253e433d59dc4d2xa266e9e0de0cb830'
  361. ``urls.py``
  362. -----------
  363. .. code-block:: python
  364. from django.conf.urls import patterns, include, url
  365. from django.conf.urls.static import static
  366. from django.views.generic.base import RedirectView
  367. from django.contrib import admin
  368. from django.conf import settings
  369. import os.path
  370. from wagtail.wagtailcore import urls as wagtail_urls
  371. from wagtail.wagtailadmin import urls as wagtailadmin_urls
  372. from wagtail.wagtaildocs import urls as wagtaildocs_urls
  373. from wagtail.wagtailsearch import urls as wagtailsearch__urls
  374. urlpatterns = patterns('',
  375. url(r'^django-admin/', include(admin.site.urls)),
  376. url(r'^admin/', include(wagtailadmin_urls)),
  377. url(r'^search/', include(wagtailsearch_urls)),
  378. url(r'^documents/', include(wagtaildocs_urls)),
  379. # For anything not caught by a more specific rule above, hand over to
  380. # Wagtail's serving mechanism
  381. url(r'', include(wagtail_urls)),
  382. )
  383. if settings.DEBUG:
  384. from django.contrib.staticfiles.urls import staticfiles_urlpatterns
  385. urlpatterns += staticfiles_urlpatterns() # tell gunicorn where static files are in dev mode
  386. urlpatterns += static(settings.MEDIA_URL + 'images/', document_root=os.path.join(settings.MEDIA_ROOT, 'images'))
  387. urlpatterns += patterns('',
  388. (r'^favicon\.ico$', RedirectView.as_view(url=settings.STATIC_URL + 'myapp/images/favicon.ico'))
  389. )