Python wagtail application














































Python wagtail application



 In the previous article we have discuss about Structural Blocks.If you have not gone through it you see through this link Structural Blocks . In this article we will learn about wagtail application.

                 How we can Create and Manage Menus of Wagtail application

Following are the step we need to follow to create and manage menus of wagtail application:-

Step 1:- Inspect Page object in Wagtail


       We can inspect page objects of our wagtail project by entering Django shell.

# cd to root directory of your Wagtail project
$ python manage.py shell

Python 3.5.0 (default, Aug 17 2017, 10:54:23)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]:


Step 2:- Basic Menu Implementation

 We will try to implement a very basic top menu in our program. It would display some specific pages such as about, welcome pages.

First, we try to add code get_context of our BlogPage model,

def get_context(self, request, *args, **kwargs):
context = super(BlogPage, self).get_context(request, *args, **kwargs)
context['posts'] = self.posts
context['blog_page'] = self

context['menuitems'] = self.get_children().filter(
live=True, show_in_menus=True)

return context

Next, we try to print the menu out in our template. So the template should look like this.

<ul class="nav navbar-nav">
{% for menu in menuitems %}
<li>
<a href="{{menu.url}}">{{menu.title}}</a>
</li>
{% endfor %}
</ul>


Step 3:- Change page order in Wagtail menu


Wagtail has built-in support for page order, so if you want to change the link order in the menu, just change the page order in Wagtail admin.

Step 4 :- Install wagtail menus


Now we like  to build menu in your Wagtail project.

  • Install wagtail menus
pip install wagtailmenus

  • Add settings below to the INSTALLED_APPS of your project settings.

INSTALLED_APPS = [
...
'wagtail.contrib.modeladmin', # Don't repeat if it's there already
'wagtailmenus',
]

  •    Add wagtailmenus.context_processors.wagtailmenus to the context_processors in your TEMPLATES. So your template settings would look like this.

'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',

'wagtailmenus.context_processors.wagtailmenus',
],

  • After all config done, run python manage.py migrate wagtailmenus to config the database

Step 5:-Render menu using wagtailmenus


We will start to use wagtailmenus to help us build a top menu. It would contain links of the blog post, and some external link

After we config the menu, now we start to modify our template to render the data of the menu.

{% load menu_tags %}


<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{{ blog_page.url }}">{{ blog_page.title }}</a>
</div>

{% main_menu template="menus/bootstrap3/main_menu_dropdown.html" %}

<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>





More Articles of SAYENDEEP MAHANTY:

Name Views Likes
C++ Exception Handling-|| 85 3
C++ Exception Handling 116 3
C++ File Handling EOF 94 5
C++ File Handling Error Handling During file Operation 1135 5
C++ File Handling seekp() Function 106 5
C++ File Handling seekg() Function 105 6
C++ File Handling tellg() Function 127 5
C++ File Handling tellp() Function 133 5
C++ File Handling close() Function 78 5
C++ File Handling:: open() 106 5
C++ File Handling Introduction 131 5
C++ Container Library:: std ::array-II 102 4
Top Django Interview Questions and Answers You Need to Know 303 6
C++ Container Library::std::array 97 6
C++ Container Library Introduction 104 5
Essential Engineering Skills for Your Resume 127 5
Mistakes To Avoid During Technical Interview 133 5
Mistakes You Must Avoid During Work From Home 179 6
Seven Common Mistakes that Beginners Should Avoid While Learning to Code 109 6
Simple Linear Regression 96 6
Python wagtailmenus 123 6
Python wagtail application 120 6
Python guppy GSL 136 5
Python wagtail guppy subpackage heapy 174 6
Python guppy Introduction 215 6
Python wagtail Structural Block 258 6
Python wagtail Integrating into Django Project 370 6
Python wagtail testing 281 7
Python wagtail Basic Block 349 7
Python wagtail image tag 216 7
Python wagtail Templates 180 6
Python wagtail Backends 206 6
Python wagtail Indexing 190 6
Python wagtail Search 173 7
Python wagtail Snippets 192 6
Python wagtail Writing your own page models 165 9
Python wagtail model class PageRevision 196 10
Python wagtail model class Site 199 9
Python wagtail wagtail core model 219 9
Python wagtail page models 189 10
Python wagtail 166 11

Comments