Skip to main content

Django Middlware to detect Dartium web browser.

Project description

django-dartium provides for a simple way to detect the Dartium web browser and make it easy to serve Dart sources instead of compiled JavaScript during development.

Installation

Python 3 and Django are the only requirements:

  1. Install django-dartium with your favorite python tool, e.g. pip install django-dartium.

  2. Add django_dartium to your INSTALLED_APPS setting.

  3. Add django_dartium.middleware.DartiumDetectionMiddleware to your MIDDLEWARE_CLASSES setting.

  4. Add two named mappings to STATICFILES_DIRS, one named dart/build which points to the build location of the JavaScript output and the other is dart/src which points to the web directory containing your original Dart source. If you created your Django project by running django-admin startproject your_project and placed your Dart sources in your_project/your_project/dart directory, then you would have the following STATICFILES_DIRS:

    STATICFILES_DIRS = [
      ('dart/build', 'your_project/dart/build/web'),
      ('dart/src', 'your_project/dart/web'),
    ]

Usage

Load the dartium tag library into your Django template, call the webcomponents tag to load the necessary polyfills and then add a reference to your Dart code via the dart tag.

A good setup would be to have the following in your base.html:

{% load dartium %}
<html>
...
<body>
  {% block content %}
  {% endblock %}

  {% webcomponents 'lite' %}
  {% block script %}
  {% endblock %}
</body>
</html>

Then in each of your pages where you want to use Dart some Dart script you can add:

{% load dartium %}
{% block content %}
  ... page content ...
{% endblock %}
{% block script %}
  {% dart "your_script.dart" %}
{% endblock %}

The end result will be that if you browse to this page with Dartium you will get served your original Dart source but if you are using any other browser you’ll be served your_script.dart.js from the build/web directory.

0.1.3 - 2017-01-31

  • New style middlware to work with Django 2.0

0.1.0

  • Initial release.

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-dartium-0.1.3.tar.gz (3.9 kB view hashes)

Uploaded Source

Built Distribution

django_dartium-0.1.3-py3-none-any.whl (5.6 kB view hashes)

Uploaded Python 3

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