Ticket #4105: simple_media_tag.patch
File simple_media_tag.patch, 2.2 KB (added by , 17 years ago) |
---|
-
django/template/defaulttags.py
771 771 return LoadNode() 772 772 load = register.tag(load) 773 773 774 #@register.simple_tag 775 def media(path=''): 776 """ 777 Returns an absolute URL pointing to the given media URL. 778 779 The optional first argument is the path to the file starting from 780 ``settings.MEDIA_URL``. 781 782 For example, if your ``MEDIA_URL`` is ``'http://media.example.com'`` 783 then in your template you can get the URL for ``css/mystyle.css`` 784 like this: 785 786 {% media 'css/mystyle.css' %} 787 788 The URL returned would be ``http://media.example.com/css/style.css``. 789 790 If no argument is given, the tag will just output the ``MEDIA_URL`` 791 (appending a trailing slash if it does not end in one). For example, 792 ``{% media %}`` would return ``http://media.example.com/``. 793 """ 794 import urlparse 795 url = settings.MEDIA_URL or '' 796 if path: 797 return urlparse.join(url, path) 798 elif not url.endswith('/'): 799 return '%s/' % url 800 return url 801 media = register.simple_tag(media) 802 774 803 #@register.tag 775 804 def now(parser, token): 776 805 """ -
docs/templates.txt
625 625 626 626 See `Custom tag and filter libraries`_ for more information. 627 627 628 media 629 ~~~~~ 630 631 Return an absolute URL pointing to the given media URL. 632 633 The optional first argument is the path to the file starting from `MEDIA_URL`_ 634 in your Django settings. 635 636 .. _MEDIA_URL: ../settings/#media-url 637 638 For example, if your ``MEDIA_URL`` is ``'http://media.example.com'`` then in 639 your template you can get the URL for ``css/mystyle.css`` like this:: 640 641 {% media 'css/mystyle.css' %} 642 643 The URL returned would be ``http://media.example.com/css/style.css``. 644 645 If no argument is given, the tag will just output the ``MEDIA_URL`` (appending 646 a trailing slash if it does not end in one). For example, ``{% media %}`` would 647 return ``http://media.example.com/``. 648 628 649 now 629 650 ~~~ 630 651