Skip to main content

Serve static files and django templates in current folder.

Project description

This is a command line utility that django-izes the current folder. This is primarily for prototyping, but can also be used for full fledged blog site.

Lets say the current folder contains a bunch of html file, this utility runs a django server, and makes the files available through it. The html files can use django’s powerful template inheritance.

Read: djangothis for blogging.

Django Templates

Any html file in the current folder is treated as a django template and is mapped to a URL mapping their location on disk. Eg index.html will become available on /index.html and so on.

Full power of django templates is available to these html files, so they can use template inheritance etc. This make creating a prototype a breeze as multiple files can inherit the look and feel of a common base.html.

Config

djangothis supports configuring django using config.yaml file if present in current folder. It can be used configure middleware, template context processors etc.

Static files

If there is a folder named static in current folder, the content of that folder will also become available on /static/ url. So static/style.css will be served on /static/style.css.

This utility also maps request to /favicon.ico to /static/favicon.ico.

views.py and forms.py

Further if file names views.py or forms.py exist, the utility “imports” them, and if those files use importd style “decorated” views or forms, they too become available (example).

Fake Ajax

Also if there is a ajax.yaml file in current folder, this utility will look for request the requested path in the yaml file, and if it exists, appropriate JSON will be returned.

Custom Tag Libraries

A folder named templatetags in current folder can be created with __init__.py and django template tag libraries, and djangothis will make them available to your templates.

Custom Commands

The current folder can contain a folder cmds, which can have django management commands stored in it, along with an __init__.py.

The command can be executed by running $ djangothis commandname.

Themes

djangothis supports theming. Theme can be placed in a special folder _theme. This folder is placed at the beginning of template dirs settings, so any template can be “overridden” by placing in it.

For the purpose of special theme specific static files, they can be placed in side _theme folder, and will be accessible via /theme/ url. Eg if there is a css file _theme/style.css, it can be accessed via /theme/style.css.

With these two features themes can be distributed as self contained folder.

Commands, Views, Custom TemplateTags and Forms in Themes

If needed a theme can contain cmds folder, templatetags folder, views.py and forms.py which will be included. For this feature to work the _theme folder needs to also contain __init__.py.

Auto Reload

The debug server reloads itself when config.yaml or ajax.yaml file is updated. Further any theme can call djangothis.watchfile(file_path) to watch a file for modifications, so that debug server can be reloaded.

Using djangothis as a static site generator

$ wget -m http://localhost:8000

Can be used to create a local mirror.

Replacing jekyll, pelican etc

djangothis can be used to replace jekyll, pelican etc. For this an appropriate views.py file has to be written and placed in the current folder or in _theme folder, which will define views for / or /blog/, that view can read the content of _posts for example, generate appropriate summary and links, define views for post etc, which serve the page.

My person website, amitu.com is powered by this, which used to be jekyll powered. The source is available on djangothis-jekyll.

Example site

Installation and Usage

To install:

$ pip install djangothis

To run from any folder that contains files as described above:

$ djangothis
Validating models...

0 errors found
Django version 1.4.1, using settings None
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

djangothis-0.9.zip (21.1 kB view details)

Uploaded Source

djangothis-0.9.tar.gz (14.1 kB view details)

Uploaded Source

File details

Details for the file djangothis-0.9.zip.

File metadata

  • Download URL: djangothis-0.9.zip
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for djangothis-0.9.zip
Algorithm Hash digest
SHA256 ee6f80cc5f02db66f5d41282358feb375d18a0983de0ea59388ab2fae9f20da4
MD5 51d046f89f45b0250506a7aaab0f4795
BLAKE2b-256 560bb86061f284b2f00eef0677b06a05cc95776b47b4a634e36c8a0e197bfa64

See more details on using hashes here.

File details

Details for the file djangothis-0.9.tar.gz.

File metadata

  • Download URL: djangothis-0.9.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for djangothis-0.9.tar.gz
Algorithm Hash digest
SHA256 a8bba8aac51758a48d5fb1cff858cf2b57cbf7dabff0d8ab472f5b342c904c4c
MD5 dcd0960e6205c83d6f6c401fb219fefd
BLAKE2b-256 66f2707f34ce6c26c21fefe62f155ca2fbd4f01bdd2f436ff4eab67d84229263

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page