A central repository for Django apps to register any static media that needs to be included.
Project description
django-mediamanager
============
A central repository for registering scripts and styles for your applications. This is similar to how the Django form media works,
except that instead of including the media in each form, they are expected to be included in some base template so they are available on every page.
This is useful when dealing with single page web apps that use client side MVC frameworks like Backbone.js and you have multiple Django apps that are providing their own media.
## Installing
Install from pip
```
sudo pip install django_mediamanager
```
Add the content processor
```python
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS
TEMPLATE_CONTEXT_PROCESSORS += (
'django_mediamanager.context_processors.media_manager_processors',
)
```
Autodiscover any media within your applications. Add this to your main urls.py
```python
import django_mediamanager
django_mediamanager.autodiscover()
```
## Adding media
Your Django applications can provide a media.py file that registers all their media. The media files are expected to be in a "static" directory within your application
Example media.py
```python
import django_mediamanager
django_mediamanager.site.add_js((
"js/bootstrap.min.js",
"js/mycooljavascript.js",
))
django_mediamanager.site.add_css({
"all": (
"css/bootstrap.css",
"css/prettystyles.css",
)
})
```
## Including media in your templates
You can use the media manager's context processors to include all the registered media in your templates. For example:
```html
<html>
<head>
{{ALL_STYLES}}
</head>
<body>
{{ALL_SCRIPTS}}
</body>
</html>
```
============
A central repository for registering scripts and styles for your applications. This is similar to how the Django form media works,
except that instead of including the media in each form, they are expected to be included in some base template so they are available on every page.
This is useful when dealing with single page web apps that use client side MVC frameworks like Backbone.js and you have multiple Django apps that are providing their own media.
## Installing
Install from pip
```
sudo pip install django_mediamanager
```
Add the content processor
```python
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS
TEMPLATE_CONTEXT_PROCESSORS += (
'django_mediamanager.context_processors.media_manager_processors',
)
```
Autodiscover any media within your applications. Add this to your main urls.py
```python
import django_mediamanager
django_mediamanager.autodiscover()
```
## Adding media
Your Django applications can provide a media.py file that registers all their media. The media files are expected to be in a "static" directory within your application
Example media.py
```python
import django_mediamanager
django_mediamanager.site.add_js((
"js/bootstrap.min.js",
"js/mycooljavascript.js",
))
django_mediamanager.site.add_css({
"all": (
"css/bootstrap.css",
"css/prettystyles.css",
)
})
```
## Including media in your templates
You can use the media manager's context processors to include all the registered media in your templates. For example:
```html
<html>
<head>
{{ALL_STYLES}}
</head>
<body>
{{ALL_SCRIPTS}}
</body>
</html>
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for django-mediamanager-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3de53e49ef0fb4311e57131668fe37023d7792494159041499283120abef0a9 |
|
MD5 | be3e2b218cbb65de900fb9899660e730 |
|
BLAKE2b-256 | 97eb38efd34e13ffbfcd08f408bd8c55f7bec49f9def3d7ce1e1f8bcb5baedfa |