Skip to content
Newer
Older
100644 110 lines (81 sloc) 3.86 KB
c350561 @coleifer Cleaning up a couple places where the docs were out-of-date and
coleifer authored Jul 27, 2010
1 Getting Started with OEmbed
2 ===========================
3
4 Installation
5 ------------
6
7 First, you need to install OEmbed. It is available at http://github.com/worldcompany/djangoembed/
8
9 ::
10
11 git clone git://github.com/worldcompany/djangoembed/
12 cd djangoembed
13 python setup.py install
14
15 Adding to your Django Project
16 --------------------------------
17
18 After installing, adding OEmbed consumption to your projects is a snap. First,
19 add it to your projects' INSTALLED_APPs and run 'syncdb'::
20
21 # settings.py
22 INSTALLED_APPS = [
23 ...
24 'oembed'
25 ]
26
27 djangoembed uses a registration pattern like the admin's. In order to be
28 sure all apps have been loaded, djangoembed should run autodiscover() in the
29 urls.py. If you like, you can place this code right below your admin.autodiscover()
30 bits::
31
32 # urls.py
33 import oembed
34 oembed.autodiscover()
35
36 Consuming Resources
37 -------------------
38
39 Now you're ready to start consuming OEmbed-able objects. There are a couple of
40 options depending on what you want to do. The most straightforward way to get
41 up-and-running is to add it to your templates::
42
43 {% load oembed_tags %}
44
45 {% oembed %}blog.content{% endoembed %}
46
47 {# or use the filter #}
48
49 {{ blog.content|oembed }}
50
51 {# maybe you're working with some dimensional constraints #}
52
53 {% oembed "600x600" %}blog.content{% endoembed %}
54
55 {{ blog.content|oembed:"600x600" }}
56
57 You can consume oembed objects in python as well::
58
59 import oembed
60 oembed.autodiscover()
61
62 # just get the metadata
63 resource = oembed.site.embed('http://www.youtube.com/watch?v=nda_OSWeyn8')
64 resource.get_data()
65
66 {u'author_name': u'botmib',
67 u'author_url': u'http://www.youtube.com/user/botmib',
68 u'height': 313,
69 u'html': u'<object width="384" height="313"><param name="movie" value="http://www.youtube.com/v/nda_OSWeyn8&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/nda_OSWeyn8&fs=1" type="application/x-shockwave-flash" width="384" height="313" allowscriptaccess="always" allowfullscreen="true"></embed></object>',
70 u'provider_name': u'YouTube',
71 u'provider_url': u'http://www.youtube.com/',
72 u'title': u'Leprechaun in Mobile, Alabama',
73 u'type': u'video',
74 u'version': u'1.0',
75 u'width': 384}
76
77 # get the metadata and run it through a template for pretty presentation
78 from oembed.consumer import OEmbedConsumer
79 client = OEmbedConsumer()
80 embedded = client.parse_text("http://www.youtube.com/watch?v=nda_OSWeyn8")
81
82 <div class="oembed oembed-video provider-youtube">
83 <object width="384" height="313">
84 <param name="movie" value="http://www.youtube.com/v/nda_OSWeyn8&fs=1"></param>
85 <param name="allowFullScreen" value="true"></param>
86 <param name="allowscriptaccess" value="always"></param>
87 <embed src="http://www.youtube.com/v/nda_OSWeyn8&fs=1"
88 type="application/x-shockwave-flash"
89 width="384"
90 height="313"
91 allowscriptaccess="always"
92 allowfullscreen="true">
93 </embed>
94 </object>
95 <p class="credit">
96 <a href="http://www.youtube.com/watch?v=nda_OSWeyn8">Leprechaun in Mobile, Alabama</a>
97 by
98 <a href="http://www.youtube.com/user/botmib">botmib</a>
99 </p>
100 </div>'
de1aaa7 Adding troubleshooting section to readme
John Maxwell authored Aug 4, 2010
101
102 Troubleshooting
103 ---------------
104
105 Problem: You try the youtube embed example, but all you get is a link to the youtube video.
106
107 Solution: Djangoembed uses fixtures to load data about oembed providors like Youtube in to the database. Try fooling around with syncdb (or migrations, if you're running South) until there are objects of type oembed.storedprovider.
108
109 If you have another problem, consider looking through the more extensive docs in the project's doc subdirectory.
Something went wrong with that request. Please try again.