{"id":438,"date":"2021-09-08T06:02:38","date_gmt":"2021-09-08T06:02:38","guid":{"rendered":"https:\/\/externlabs.com\/blogs\/?p=438"},"modified":"2023-04-03T16:04:39","modified_gmt":"2023-04-03T10:34:39","slug":"wagtail-cms-for-python-django","status":"publish","type":"post","link":"https:\/\/externlabs.com\/blogs\/wagtail-cms-for-python-django\/","title":{"rendered":"Wagtail CMS: Python CMS for Django"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Wagtail is a Python-based CMS made for Django. The <a href=\"https:\/\/wagtail.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">Wagtail CMS<\/a> was released in 2015 by a digital agency named Torchbox, the same agency that created South migrations for Django in 2008. So when we encountered a project that required a content management system, we had an additional reason to give Wagtail CMS a try. We decided to try it out in practice.<\/p><div id=\"ez-toc-container\" class=\"ez-toc-v2_0_63 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Page Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/externlabs.com\/blogs\/wagtail-cms-for-python-django\/#Explanation_to_Wagtail_Python_CMS\" title=\"Explanation to Wagtail Python CMS\">Explanation to Wagtail Python CMS<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/externlabs.com\/blogs\/wagtail-cms-for-python-django\/#Why_We_use_Wagtail\" title=\"Why We use Wagtail\">Why We use Wagtail<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/externlabs.com\/blogs\/wagtail-cms-for-python-django\/#Installation_and_setup\" title=\"Installation and setup\">Installation and setup<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/externlabs.com\/blogs\/wagtail-cms-for-python-django\/#Configuration_URL\" title=\"Configuration URL\">Configuration URL<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/externlabs.com\/blogs\/wagtail-cms-for-python-django\/#Admin_Interface_for_Wagtail_CMS\" title=\"Admin Interface for Wagtail CMS\">Admin Interface for Wagtail CMS<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/externlabs.com\/blogs\/wagtail-cms-for-python-django\/#Difference_between_Django_CMS_and_Wagtail\" title=\"Difference between Django CMS and Wagtail\">Difference between Django CMS and Wagtail<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Explanation_to_Wagtail_Python_CMS\"><\/span>Explanation to Wagtail Python CMS<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Compared to other famous content management systems like Django Content Management System, which provides a ton of flexibility to the administrator (content manager) at the cost of interface complexity, the Wagtail CMS has a rather simple interface with minimum settings. And all of these settings and functionality have to be implemented in code. Content managers can only use a set of tools that are implemented programmatically as&nbsp;<a target=\"_blank\" href=\"https:\/\/externlabs.com\/blogs\/top-10-python-frameworks-for-game-development\/\" rel=\"noreferrer noopener\">Python classes<\/a>&nbsp;or so-called blocks.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Wagtail provides a lightweight and straightforward interface<\/li>\n\n\n\n<li>In Wagtail as all querying and database use can be fully controlled by the developer.<\/li>\n\n\n\n<li>Wagtail provides Ease and speed of development because\u00a0Wagtail is <a href=\"https:\/\/externlabs.com\/hire-python-developer.php\">Django<\/a> and uses Django\u2019s authentication backend, templating system, and so on.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Why_We_use_Wagtail\"><\/span>Why We use Wagtail<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We use Wagtail for the CMS (content management system) in the Django rest framework. Because for cms, we need to create templates for every API but<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Wagtail provides its admin with a frontend interface. We connect Django rest APIs to the wagtail framework with wagtail models.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>models.py<\/em><\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Installation_and_setup\"><\/span>Installation and setup<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">For Django, we install Wagtail through pip<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>$ pip install wagtail<\/em><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After installing Wagtail, we setup the configuration in the settings.py file in the installed apps:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Settings.py<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Add the wagtail Site name in settings.py. This will be displayed on the main dashboard of the Wagtail admin backend:-<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Configuration_URL\"><\/span>Configuration URL<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">We configure urls.py in our project directory with the wagtail URLs<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>urls.py<\/em><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">wagtailadmin_urls provides the admin interface for Wagtail. This is separate from the Django admin interface:-<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Admin_Interface_for_Wagtail_CMS\"><\/span>Admin Interface for Wagtail CMS<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Login admin in Wagtail<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the Wagtail CMS, pages are Django models. Pages inherit from the abstract Wagtail Page model, which has all the service methods, fields, and properties needed by a page. We use Rich Text Field in our Django ems project, so we implement wagtail models:-<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>models.py<\/em><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In EMS projects, we use different \u2014 2 Wagtail models for many purposes like: for birthday (BirthdayPage Model), upcoming holiday (UpcomingHoliday Model), etc. We\u2019ve used a standard Django&nbsp;<em>CharField<\/em>&nbsp;in these models and a field from the Wagtail CMS called RichTextField.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To be able to preview our new page, we need to create a template for it. A template file must be placed either in the project\u2019s&nbsp;<em>templates<\/em>&nbsp;directory (under the blog subdirectory) or inside the application&nbsp;<em>templates<\/em>&nbsp;directory. It must be named exactly like in the model.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The page will automatically be registered in the admin interface, so all left is to create and apply a migration.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, we open a birthday page this looks like this, and we fill in all the details on this page. We can view all data in Django, admin form wagtail admin.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Django-admin View of pages:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here wagtail data is showing in the Django-admin table<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Difference_between_Django_CMS_and_Wagtail\"><\/span>Difference between Django CMS and Wagtail<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Django-cms and Wagtail are both based on the Django framework. It is very similar to the classic Django-admin page. The Django CMS admin style overrides Django admin\u2019s base_site.html, but you can still partially customize this page.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Django-CMS might use the Django admin as its admin page; it creates custom templates to make the page look more decent. But this implementation also brings some problems. If your existing application, which has an existing admin app, wants to integrate Django-CMS to add some CMS functions, Django-CMS might not work very well in this scenario.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Django-CMS is not more flexible than Wagtail because, in Wagtail, we easily extend the model and integrate CMS into your existing project.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Wagtail is a Python-based CMS made for Django. The Wagtail CMS was released in 2015 by a digital agency named Torchbox, the same agency that created South migrations for Django in 2008. So when we encountered a project that required a content management system, we had an additional reason to give Wagtail CMS a try.&hellip;<\/p>\n","protected":false},"author":2,"featured_media":6226,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"content-type":"","footnotes":""},"categories":[43],"tags":[152],"class_list":["post-438","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-python-frameworks"],"_links":{"self":[{"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/posts\/438","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/comments?post=438"}],"version-history":[{"count":0,"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/posts\/438\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/media\/6226"}],"wp:attachment":[{"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/media?parent=438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/categories?post=438"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/externlabs.com\/blogs\/wp-json\/wp\/v2\/tags?post=438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}