Skip to main content

Re-usable bussiness components, modular units on a page

Project description

django-webnodes
===============

The goal of `django-webnodes` is to create a new way of writing django templates which is fully compatible with the current django templating infrastructure.

It's born to make it easy to support standard, reusable `bussiness components` across your application.

`django-webnodes` are like special functional calls to render components of your page.

## Usage:

This use as django templatetags

{% webnode node_name [value1 value2 ... key1=value1 key2=value2 ...] %}

- ``value1``: position value passed as ``value1`` in ``get_context()`` and ``render()`` methods
- ``key1=value1``: dictionary key-value pairs passed as ``key1`` in ``get_context()`` and ``render()`` methods

## Demo

For example, if you are implementing a app statistics website, and you want to have app ratings appear on both list page and detail page, you can make an `RatingsNode` to render them on both pages.

First, create a Python module for your webnodes, e.g., webnodes.py(place it in ``yourapp`` module)

from webnodes import WebNode


class RatingsNode(WebNode):

template = 'webnodes/ratings.html'

def get_context(self, app_id):
...
ratings = ...
return {'ratings': ratings}

Calling from template:

{% load webnode %}

<p>{% webnode RatingsNode app.id %}</p>

## Extension

If you want see this webnode independently, you can add this in your urls' urlpatterns

url(r'^webnodes/', include('webnodes.ext.urls'))

Then open `http://127.0.0.1:8000/webnodes/RatingsNode?app_id=414603431` in your browser, you will see it.

## Why use this?

1. Decoupling the logic of front-end and back-end separately;
2. Make each component as a webnode will improve cohesion(because each component's template and data(include the logic of fetch data) are always strongly correlated);
3. We can test each component independently;
4. easy to realize partial renewal.

## Todos

support css and javascript

# Refs

Inspired by [tornado UI Module](https://github.com/facebook/tornado/blob/master/tornado/web.py), [django custom templatetags](https://docs.djangoproject.com/en/dev/howto/custom-template-tags/).

Based on [django-widgets(1)](https://code.google.com/p/django-widgets) and [django-widgets(2)](https://github.com/marcinn/django-widgets)

Project details


Download files

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

Source Distribution

django-webnodes-0.0.2.tar.gz (4.1 kB view details)

Uploaded Source

File details

Details for the file django-webnodes-0.0.2.tar.gz.

File metadata

File hashes

Hashes for django-webnodes-0.0.2.tar.gz
Algorithm Hash digest
SHA256 aae8f0e3fc25586c80a6fb2b54997699827e1e7b22a8cda62fbe351bd51d7e3c
MD5 52cbb4d927e5bf4c992db7a0bfccdc11
BLAKE2b-256 a86e3556bc3a768d265623656204c0e4d58a92edd4382a8f0482719618011cb5

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