Loading docs/syndication_feeds.txt +7 −0 Original line number Diff line number Diff line Loading @@ -245,6 +245,13 @@ request to the URL ``/rss/beats/0613/``: subclass of ``ObjectDoesNotExist``. Raising ``ObjectDoesNotExist`` in ``get_object()`` tells Django to produce a 404 error for that request. **New in Django development version:** The ``get_object()`` method also has a chance to handle the ``/rss/beats/`` url. In this case, ``bits`` will be an empty list. In our example, ``len(bits) != 1`` and an ``ObjectDoesNotExist`` exception will be raised, so ``/rss/beats/`` will generate a 404 page. But you can handle this case however you like. For example you could generate a combined feed for all beats. * To generate the feed's ``<title>``, ``<link>`` and ``<description>``, Django uses the ``title()``, ``link()`` and ``description()`` methods. In the previous example, they were simple string class attributes, but this Loading tests/regressiontests/syndication/__init__.py 0 → 100644 +0 −0 Empty file added. tests/regressiontests/syndication/tests.py 0 → 100644 +14 −0 Original line number Diff line number Diff line # -*- coding: utf-8 -*- from django.test import TestCase from django.test.client import Client class SyndicationFeedTest(TestCase): def test_complex_base_url(self): """ Tests that that the base url for a complex feed doesn't raise a 500 exception. """ c = Client() response = c.get('/syndication/feeds/complex/') self.assertEquals(response.status_code, 404) tests/regressiontests/syndication/urls.py 0 → 100644 +18 −0 Original line number Diff line number Diff line from django.conf.urls.defaults import patterns from django.core.exceptions import ObjectDoesNotExist from django.contrib.syndication import feeds class ComplexFeed(feeds.Feed): def get_object(self, bits): if len(bits) != 1: raise ObjectDoesNotExist return None urlpatterns = patterns('', (r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', { 'feed_dict': dict( complex = ComplexFeed, )}), ) tests/urls.py +3 −0 Original line number Diff line number Diff line Loading @@ -19,4 +19,7 @@ urlpatterns = patterns('', (r'^middleware/', include('regressiontests.middleware.urls')), (r'^utils/', include('regressiontests.utils.urls')), # test urlconf for syndication tests (r'^syndication/', include('regressiontests.syndication.urls')), ) Loading
docs/syndication_feeds.txt +7 −0 Original line number Diff line number Diff line Loading @@ -245,6 +245,13 @@ request to the URL ``/rss/beats/0613/``: subclass of ``ObjectDoesNotExist``. Raising ``ObjectDoesNotExist`` in ``get_object()`` tells Django to produce a 404 error for that request. **New in Django development version:** The ``get_object()`` method also has a chance to handle the ``/rss/beats/`` url. In this case, ``bits`` will be an empty list. In our example, ``len(bits) != 1`` and an ``ObjectDoesNotExist`` exception will be raised, so ``/rss/beats/`` will generate a 404 page. But you can handle this case however you like. For example you could generate a combined feed for all beats. * To generate the feed's ``<title>``, ``<link>`` and ``<description>``, Django uses the ``title()``, ``link()`` and ``description()`` methods. In the previous example, they were simple string class attributes, but this Loading
tests/regressiontests/syndication/tests.py 0 → 100644 +14 −0 Original line number Diff line number Diff line # -*- coding: utf-8 -*- from django.test import TestCase from django.test.client import Client class SyndicationFeedTest(TestCase): def test_complex_base_url(self): """ Tests that that the base url for a complex feed doesn't raise a 500 exception. """ c = Client() response = c.get('/syndication/feeds/complex/') self.assertEquals(response.status_code, 404)
tests/regressiontests/syndication/urls.py 0 → 100644 +18 −0 Original line number Diff line number Diff line from django.conf.urls.defaults import patterns from django.core.exceptions import ObjectDoesNotExist from django.contrib.syndication import feeds class ComplexFeed(feeds.Feed): def get_object(self, bits): if len(bits) != 1: raise ObjectDoesNotExist return None urlpatterns = patterns('', (r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', { 'feed_dict': dict( complex = ComplexFeed, )}), )
tests/urls.py +3 −0 Original line number Diff line number Diff line Loading @@ -19,4 +19,7 @@ urlpatterns = patterns('', (r'^middleware/', include('regressiontests.middleware.urls')), (r'^utils/', include('regressiontests.utils.urls')), # test urlconf for syndication tests (r'^syndication/', include('regressiontests.syndication.urls')), )