Skip to main content

Utilities for building responsive websites in Django.

Project description

https://travis-ci.org/mlavin/django-responsive.svg?branch=master

django-responsive a utility application for building responsive websites in Django. This tool is meant to complement the use of CSS media queries and help solve problems with fixed width elements such as advertisements or embedded video.

This project does not match devices based on user agent strings and instead uses a small piece of javascript to make the device window size available on the server. Once enabled you can access a device_info dictionary in your templates:

{'width': 320, 'type': 'phone', 'height': 480}

Now you and conditionally render content based on the device size or type.

Installation

django-responsive requires Python 2.6 or 2.7 and django>=1.3. There is experimental support for Python 3.2 if using Django >= 1.5. It is easiest to install django-responsive from PyPi using pip:

pip install django-responsive

Configuration

To enable django-responsive you will need to update your MIDDLEWARE_CLASSES and TEMPLATE_CONTEXT_PROCESSORS settings.:

MIDDLEWARE_CLASSES = (
    # Other middleware classes go here
    'responsive.middleware.DeviceInfoMiddleware',
)

TEMPLATE_CONTEXT_PROCESSORS = (
    # Other context processors included here
    'responsive.context_processors.device_info',
)

Note that TEMPLATE_CONTEXT_PROCESSORS is not included in the default settings and you should be careful to not lose the defaults when adding this additional context processor.

There is an optional setting RESPONSIVE_BREAKPOINTS which is used to determine the type included in the device_info dictionary. The default breakpoints are:

# Name, Max Width (inclusive)
DEFAULT_BREAKPOINTS = {
    'phone': 480,
    'tablet': 767,
    'desktop': None,
}

To overwrite the default breakpoints, include a RESPONSIVE_BREAKPOINTS dictionary in the project’s settings.py file:

# Name, Max Width (inclusive)
RESPONSIVE_BREAKPOINTS = {
    'phone': 480,
    'tablet': 767,
    'desktop': None,
}

License

django-responsive is released under the BSD License. See the LICENSE file for more details.

Contributing

If you think you’ve found a bug or are interested in contributing to this project check out django-responsive on Github.

Running the Tests

You can run the tests with via:

python runtests.py

If you see any test failures please report them to the Github issue tracker.

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-responsive-0.3.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

django_responsive-0.3.0-py2.py3-none-any.whl (11.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-responsive-0.3.0.tar.gz.

File metadata

File hashes

Hashes for django-responsive-0.3.0.tar.gz
Algorithm Hash digest
SHA256 f6e2b2b7661914b4dc07ef13f372ee36fe2eb1dcaf5888f4f34031395b84f12d
MD5 39de7df11800b89c4220cf61fc528988
BLAKE2b-256 1a5fc745fbe71f3fda3ba96a74bad9edd49f98008579e8c7c927fa8d0cc220e4

See more details on using hashes here.

File details

Details for the file django_responsive-0.3.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_responsive-0.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 332cf5408f958cf5f411a95dbb68a29ceb3932c21e35ca944b34bed098008abf
MD5 0eef27c0287cadcfcdf67c4daa09e0c1
BLAKE2b-256 93a87462034b8c3671862ab0decc673528e6abd05fba168f31abffb54b9fbb81

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