Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install django-subview

How to install django-subview

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install django-subview
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.1.2 Available View build log
0.1.1 Available View build log
0.1 Available View build log
Windows (64-bit)
0.1.2 Available View build log
0.1.1 Available View build log
0.1 Available View build log
Mac OS X (10.5+)
0.1.2 Available View build log
0.1.1 Available View build log
0.1 Available View build log
Linux (32-bit)
0.1.2 Available View build log
0.1.1 Available View build log
0.1 Available View build log
Linux (64-bit)
0.1.2 Available View build log
0.1.1 Available View build log
0.1 Available View build log
 
Author
Lastest release
version 0.1.2 on Mar 13th, 2012

django_subview is a module to include complete views with application logic into templates and to retrieve them by a single, generic url.

What is this for?

In the AJAX world, there are often parts in a page, that contain an own, self-contained and reusable application logic. Call it pagelet, portlet, partial, subcontroller, ... we call it subview, corresponding to Djangos Model/View/Template structure. This is because it is just a normal view that is included into the response of another view.

Example use case: Imagine the frontpage of a blog page. A module with the latest 5 comments should reload every minute. 1. This module should be included in the frontpage 2. It has to be rendered "standalone" for an AJAX request

Include view in template

A view can simply included in a template as shown below.

{% subview "path.to.some_view" name1=value1 name2=value2 %}

The first argument is a path to a view. It can be an absolute Python path or just app_name.view_name without the project name if the view is located inside the project.

View parameters are space-separated values that are passed to the view function. Only keyword arguments are supported. All arguments for the view should be present or have default values.

For example if you have a view app_name.latestcomments taking client's id and the view has the following signature:

def latestcomments(request, amount):

then in a template you can call the subview for a certain client like this:

{% subview "app_name.latestcomments" amount=5 %}

Call view with generic URL

### What is this for? ###

Often, subviews are reusable, self contained components and are not intended to be opened standalone in a browser. So you don't have to define a url for each view but can access it from your ajax app through a generic URL.

### Example ###

You have to include the bundled urlpatterns in your root urlconf like this:

urlpatterns = patterns('',
url(r'^subview', include('subview.urls')),

System Message: WARNING/2 (<string>, line 56)

Definition list ends without a blank line; unexpected unindent.

)

Now you simply can request a view from your browser like:

http://127.0.0.1:8000/subview/myapp.views.latestcomments/{"amount":"5"}?some=parameter

Please bear in mind that this excample is not urlencoded for readability. The real request should look like:

http://127.0.0.1:8000/subview/myapp.views.latestcomments/%7B"amount":"5"%7D?some=parameter

GET and POST parameters aren't affected in any way. This means you can use and access them as usual from within your view / subview.

Subscribe to package updates

Last updated Mar 13th, 2012

Download Stats

Last month:3

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.