Posts tagged with "Django"
  • Last modified July 20, 2012, 4:28 p.m.
    Posted July 20, 2012, 4:13 p.m. by admin

    So I have been meaning to do this for a while but have only just managed to get around to it.

    The code by which this very blog is implemented is now available as a Django app. Hooray!

    I implemented my own blog app not liking what was already available for Django. There were some good ones out there, but they did too much when all I required was a simple system that took care of comments, tags and most importantly allowed me to create posts using a rich text editor that supported the uploading of inline images. I also needed something that displayed code blocks with syntax highlighting. With those goals in mind I started implementing my requirements.

    The result: django-richtext-blog!

    I had always intended to release it to the wider community but needed to spend time packaging it up and providing some documentation.

    The very blog you're reading is implemented with this app, so if you like what you see, give it a try!

    The simplest way to get it installed is to run:

    $ pip install django-richtext-blog
    

    Providing your python environment provides pip. Then just follow the instructions to get the app running in Django.

    Currently it only runs under Django 1.3 due to dependencies. In the future I plan to make it Django 1.4 compatible.

    Python Package Index listing:

    http://pypi.python.org/pypi/django-richtext-blog

    GitHub project page:

    https://github.com/timmygee/django-richtext-blog

    Issues and bugs can be reported to the project issues tracker.

    If you have any queries about the app please get in touch with me at my contact page.

  • Last modified May 24, 2012, 1:14 a.m.
    Posted May 15, 2012, 11:45 p.m. by admin

    Getting emacs right when it comes to making it Django dev friendly can be fiddly. Here's how I did it.

    I did this on Debian 7 "wheezy", so your mileage may vary. I would imagine you will have similar results on a recent version of Ubuntu.

    Step 1 - Install and configure django html syntax highlighting

    First, get the files in place

    cd ~/.emacs.d
    wget http://ourcomments.org/Emacs/DL/elisp/nxhtml/zip/nxhtml-2.08-100425.zip
    unzip nxhtml-2.08-100425.zip
    

    Next, edit your .emacs file. I've used vim as the editor here but feel free to use what you're most comfortable with. Even emacs will do!

    cd ~/
    vim .emacs
    

    Add the following lines of code to the end of the file.

    ;; ---------------------------------------------------------------------------
    ;; For django html
    (autoload 'django-html-mumamo-mode "~/.emacs.d/nxhtml/autostart.el")
    (setq auto-mode-alist
    (append '(("\\.html?$" . django-html-mumamo-mode)) auto-mode-alist))
    (setq mumamo-background-colors nil)
    (add-to-list 'auto-mode-alist '("\\.html$" . django-html-mumamo-mode))
    

    Try running emacs. If you get the following error:

    Warning: 'font-lock-beginning-of-syntax-function' is an obsolete variable (as
    of Emacs 23.3); use 'syntax-begin-function' instead.
    

    Run this from the command line:

    replace font-lock-beginning-of-syntax-function syntax-begin-function -- .emacs.d/nxhtml/util/mumamo.el
    

    Step 2 - Configure a colour scheme

    I generally work in a terminal with white text on a black background so my theme choice was color-theme-hober. After the colour scheme is installed there is a ton to chose from. From within emacs META-x, then type "color-theme-". Tap the tab key a couple of times to see all the options.

    If you're using Ubuntu/Debian the colour theme should be an installable package via apt. I took most of these steps from this resource here.

    If you can't use apt, you can download the colour themes from here. Otherwise run:

    sudo apt-get install emacs-goodies-el
    

    From a terminal (once again you can use your editor of choice here).

    vim ~/.emacs
    

    Add the lines:

    ;; ---------------------------------------------------------------------------
    ;; Color-theme
    (add-to-list 'load-path "/usr/share/emacs/site-lisp/emacs-goodies-el/color-theme.el")
    (require 'color-theme)
    (eval-after-load "color-theme"
    '(progn
    (color-theme-initialize)
    (color-theme-hober)))
    

    Replace "color-theme-hober" with another option if you prefer a different colour scheme.

    Step 3 - Add an 80 character column marker

    This step is optional but it's a nice way to get emacs to tell you that you're going over the standard 80 character terminal width.

    Taken from instructions here.

    Install the colomn-marker feature by running the following from a terminal:

    cd ~/.emacs.d
    wget http://www.emacswiki.org/emacs/download/column-marker.el
    

    Once again, edit your .emacs file and add the following lines to the bottom:

    ;; ---------------------------------------------------------------------------
    ;; Column Marker
    (require 'column-marker)
    (add-hook 'python-mode-hook (lambda () (interactive) (column-marker-1 79)))
    

    Note that the column-marker-1 value is 79 not 80. This is because emacs will wrap one character early if a line reaches 80 characters.

    Run emacs again. If you get loading issues add the following to the top of your .emacs file:

    (add-to-list 'load-path "~/.emacs.d/") 
    

    Step 4 - Additional configurations

    Below are some more configurations you can add to emacs that I find rather handy.

    Add any of these code snippets to the end of your .emacs file

    For adding the shortcut key combination META-g to bring up the goto-line feature:

    ;; Set goto line
    (global-set-key "\M-g" 'goto-line)
    

    Ensure files when saved end with a newline character:

    ;; Always end a file with a newline
    (setq require-final-newline t)
    

    Switch off the menu bar I find pretty useless and free up another line for text!

    ;; Turn off menu bar
    (menu-bar-mode -1)
    

    For posterity - here's my whole .emacs file with all configs in one:

    (add-to-list 'load-path "~/.emacs.d/")
    
    ;; ---------------------------------------------------------------------------
    ;; Column Marker
    (require 'column-marker)
    (add-hook 'python-mode-hook (lambda () (interactive) (column-marker-1 79)))
    
    ;; ---------------------------------------------------------------------------
    ;; For django html
    (autoload 'django-html-mumamo-mode "~/.emacs.d/nxhtml/autostart.el")
    (setq auto-mode-alist
    (append '(("\\.html?$" . django-html-mumamo-mode)) auto-mode-alist))
    (setq mumamo-background-colors nil)
    (add-to-list 'auto-mode-alist '("\\.html$" . django-html-mumamo-mode))
    
    ;; ---------------------------------------------------------------------------
    ;; Color-theme
    (add-to-list 'load-path "/usr/share/emacs/site-lisp/emacs-goodies-el/color-theme.el")
    (require 'color-theme)
    (eval-after-load "color-theme"
    '(progn
    (color-theme-initialize)
    (color-theme-hober)))
    
    ;; Set goto line
    (global-set-key "\M-g" 'goto-line)
    
    ;; Always end a file with a newline
    (setq require-final-newline t)
    
    ;; Turn off menu bar
    (menu-bar-mode -1)