Kharghost

Introduction

Kharghost is a blogging-tool inspired by Ghost, thus the name.
It is web software you can use to create beautiful Blogs with bootstrap themes and host it anywhere you want (download page (zip/tar.gz with instructions)).

For the demo-hosting please visit Kharghost-Heroku

View the source-code and contribute on it through Github

Team

Member Name Responsibilities
Nikhil Hassija Layout and design (Bootstrap/HTML/CSS)
Parth Mittal Backend (django)
Jai Luthra Backend (django) and JS
Tushar Kataria Content and templates

Goal

To learn designing a website from scratch, and get acquainted to Model-view architecture for making webapps.

Area and Initial Planning

We wanted to build a solution for blogging which is free and open source, works on Python (django) and gives you the freedom to host it yourself and manage your content easily.

Tools used

  • Django as the backend, with SQLite database
  • Python-anywhere for hosting a sample application (for demonstration)
  • Heroku for hosting a sample application (for demonstration)
  • Github for hosting and collaborating on the code
  • Bootstrap for layout and themes
  • Markdown (python package) for the post-writing interface, which gets converted to HTML on the fly and works like a WYSIWYG editor
  • Disqus for commenting system.

Learning journey

  • We started out by making a rough sketch of what all features our platform should offer
  • Then we created the Models (python classes that represent tables in the SQL database) . This helped the site get a logical structure (posts, authors etc)
  • Then we created the Views (python functions that are called when a GET request occurs). This represents the data stored in the tables for rendering as HTML.
  • Then we created the Templates (HTML pages with some variables that get pulled from views). This completed our frontend and linked the views with actual HTML that will be shown on a GET request
  • Finally we touched up everything, tested if things worked as they should, created sample posts and pushed it to the demo web server

Snippets and Screenshots

Views

def post_view(request, post_id):
    post = get_object_or_404(Post, id=post_id)
    if (request.user.is_authenticated()):
        template = "blog/writer.html"
    else:
        template = "blog/reader.html"
 
    if request.user.is_authenticated() and request.method == "POST":
        edit_text = request.POST['text']
        post.markdown_text = edit_text
        post.html_text = markdown(post.markdown_text, safe_mode='escape', extensions=['magic'])
        post.save()
 
    context = {'post' : post, 'user' : request.user}
    return render(request, template, context=context)

Templates

{% extends "blog/base.html" %}
 
{% block body %}
    <div class="container" id="content">
        <h1 class="text-center">{{ post.title }}<small> {{ post.author }} | {{ post.pub_date | date }}</small></h1>
        {{ post.html_text | safe }}
    </div>    
{% endblock body %}

Models

from django.db import models
from django.contrib.auth.models import User
from django.utils import timezone
 
class Post(models.Model):
    title = models.CharField(max_length=100, default='')
    markdown_text = models.TextField(default='')
    html_text = models.TextField()
    pub_date = models.DateTimeField()
    author = models.ForeignKey(User)
    id = models.AutoField(primary_key=True)
 
    def __str__ (self):
        return self.title

To see our complete source-code please visit our Github Repo. The code is open-source, licensed under MIT License.

Screenshots

Features

  • Multiple themes

  • On-the-fly Markdown editing
  • Custom hosting (like wordpress)
  • Freedom to customize using your django-fu
  • Open Source :)
  • Comments (using Disqus)

Installation

Download the zip file or clone the github repo
(Prerequisites: Python 3)

Create a virtualenv
$ virtualenv -p /usr/bin/python3 venv

Activate it
$ source venv/bin/activate

Enter the cloned/extracted repo and install requirements
$ pip install -r requirements.txt

Copy the local_settings file if you want to run the server locally
$ cp local_setttings_sample.py local_settings.py

Make migrations (delete any existing db.sqlite3 file before)
$ python manage.py makemigrations blog
$ python manage.py migrate

Create an admin user
$ python manage.py createsuperuser

Run the server and achieve glory
$ python manage.py runserver

Go to localhost:8000/admin and login with your credentials
Create users for blog authors, and start bloggin' away :)

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License