+++ title = "w3blog, a simple blog engine" date = 2018-07-23T02:05:00Z +++ ![w3blog](preview.png) In this post I will be explaining how to use my blog engine for the Django framework, w3blog. ## First, an introduction I decided to create my own blog engine because I didn't find one for Django that satisfied my needs. That is, I wanted a simple to setup, but customizable blog engine that offered multilingual capabilities since I wanted to write my blog in three different languages (English, Spanish and Russian). I wanted to be able to write posts in different languages and make use of Django's built-in localization engine, so that if user's locale is, for example, Spanish, so that they would immediately see the posts in Spanish, if they are already translated to Spanish. The following is a short list of features of w3blog: * Users can post anonymous comments, if enabled * Allow only registered users to post comments through Django's built-in authentication engine, if enabled * Can use own base template * RSS * Turn on or off the sidebar, and chose to show categories, archive list, none, or both in the sidebar * Show or hide the author of the post, and whether it shows the author's name or username * Enable or disable multilingual features These are features available as of the writing of this post (v0.4.2). In the next version (v0.5.x) I plan on adding the ability to further customize the sidebar without having to modify the internal templates of the app. I will be showing you further down below how to setup the engine to customize these features. ## Setup First of all, you need to install a couple of python modules with pip. w3blog itself, and django-summernote. Check out https://summernote.org/ for more information about it. ```sh $ pip install w3blog django-summernote ``` After installing them, we need to add to the settings.py list of installed apps ```py INSTALLED_APPS = [ '...', 'django_summernote', 'weblog', ] ``` And add the following urls to our project's main urls.py ```py url(r'^blog/', include('weblog.urls')), url(r'^summernote/', include('django_summernote.urls')), ``` So if we now run our development server and go to our browser to the respective link, we should now see something similar to the following ![w3blog home page on first launch](first_launch.jpg) After creating a django super user and going to the admin, we can now see a weblog section with two models: Blog posts and Categories. ![Admin panel on first launch](admin1.png) We can add a category ![Adding a category](add_category.png) We could try and add a post now ![Adding a post](add_post.png) Chose a slug (the portion of the url for the post), the categor(y/ies), whether we want it to be available to the reader after saving (Published) and the date and time of publication. ![Publishing a post](publish_post.png) After adding our post, the page now looks like this ![A published post](published_post.png) I will better explain what the options above mean next. ## Configuration That already looks much like a blog, but what if we wanted to use our own base template (the one containing the header/navbar), or show the categories on the sidebar. If you want to change the settings for w3blog, you need to add the `WEBLOG_SETTINGS` dictionary to your settings.py. The following are available settings that you can change (with their defaults): ```py WEBLOG_SETTINGS = { 'enable_comments': False, 'allow_anon_comments': False, 'multilingual': True, 'blog_title': 'Django-Weblog', 'base_template': 'weblog_base.html', 'show_author': True, 'use_authors_username': True, 'show_sidebar': True, 'show_categories': False, 'show_archive': True, 'posts_per_page': 10, 'enable_rss': True, 'home_title': 'Welcome to the blog!', } ``` So most of them are pretty self explanatory, but I will explain them to avoid confusion nonetheless: * enable_comments -- set to True to enable users to post comments on the posts. * allow_anon_comments -- allow anonymous comments. * multilingual -- enable multilingual features, i.e. translations of posts. * blog_title -- the title of the blog, will be used on the blog's homepage and title tag * base_template -- which base template to use. If not set, will use w3blog's default template. * show_author -- set to True to display the author of the post on each post * use_authors_username -- set to True to use the author's username (e.g. author66) instead of their full name (e.g. John Smith). * show_sidebar -- set to True to show the sidebar (where the category and archive lists reside). * show_categories -- set to True to show the categories list on the sidebar (won't show if you disabled the sidebar) * show_archive -- set to True to show the archive list on the sidebar (won't show if you disabled the sidebar) * posts_per_page -- the number of pages to display per page. * enable_rss -- set to True to enable the RSS feed (/rss) * home_title -- if set, it will display on the blog's home page instead of blog_title (but blog_title will display in the title tag). Now, you most probably will want to use your own template, in that case, make sure to add the following to your template's head tag ```jinja2