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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file django-dartium-0.1.3.tar.gz.

File metadata

File hashes

Hashes for django-dartium-0.1.3.tar.gz
Algorithm Hash digest
SHA256 2c33ebc7b21dc70054dfc7947a6285c902dfacf8dbd60a17f8420909469a6792
MD5 2a1aa871459f557acbd4134646e3f0bf
BLAKE2b-256 ac1c57b96206afdac25d596d65a1a6b90bc5225ade052b66f25238456c35303e

See more details on using hashes here.

File details

Details for the file django_dartium-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for django_dartium-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6a42e284924fcd4833fa3eae71431126de74341176f7f902c8d36a383d98f766
MD5 0b8797b92bb92928f50389a051daa161
BLAKE2b-256 27fd83137ce267d0c4cea98a90e8f1389f5b3a899d1bf31e27631a039dd7a34e

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