8000 Cleaned up apphooks documentation · django-cms/django-cms@5a04c25 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5a04c25

Browse files
committed
Cleaned up apphooks documentation
* fixes #6377 [ci only docs]
1 parent 32d9b73 commit 5a04c25

File tree

2 files changed

+36
-32
lines changed

2 files changed

+36
-32
lines changed

docs/how_to/apphooks.rst

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,30 @@ The file needs to contain a :class:`CMSApp <cms.app_base.CMSApp>` sub-class. For
3636
return ["myapp.urls"] # replace this with the path to your application's URLs module
3737

3838
.. versionchanged:: 3.3
39-
``CMSApp.get_urls()`` replaces ``CMSApp.urls``. ``urls`` is now deprecated and will be removed in
40-
version 3.5.
39+
``CMSApp.get_urls()`` replaces ``CMSApp.urls``. ``urls`` was removed
40+
in version 3.5.
41+
42+
43+
Apphook URLS
44+
============
45+
46+
Instead of defining the URL patterns in another file ``myapp/urls.py``, it also is possible
47+
to return them directly, for instance as:
48+
49+
.. code-block:: python
50+
51+
from django.conf.urls import url
52+
from myapp.views import SomeListView, SomeDetailView
53+
54+
class MyApphook(CMSApp):
55+
# ...
56+
def get_urls(self, page=None, language=None, **kwargs):
57+
return [
58+
url(r'^$', SomeListView.as_view()),
59+
url(r'^(?P<slug>[\w-]+)/?$', SomeDetailView.as_view()),
60+
]
61+
62+
However, it's neater to keep them in the application's ``urls.py``, where they can easily be reused.
4163

4264

4365
Apphooks for namespaced applications

docs/introduction/05-apphooks.rst

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,36 +34,16 @@ This is a very basic example of an apphook for a django CMS application:
3434
name = _("Polls Application")
3535
3636
def get_urls(self, page=None, language=None, **kwargs):
37-
return ["polls.urls"]
37+
return ["polls.urls"] ]
3838
3939
40-
Instead of defining the URL patterns in another file ``polls/urls.py``, it also is possible
41-
to return them directly, for instance as:
40+
In this ``PollsApphook`` class, we have done several key things:
4241

43-
.. code-block:: python
44-
45-
from django.conf.urls import url
46-
from polls.views import PollListView, PollDetailView
47-
48-
class PollsApphook(CMSApp):
49-
# ...
50-
def get_urls(self, page=None, language=None, **kwargs):
51-
return [
52-
url(r'^$', PollListView.as_view()),
53-
url(r'^(?P<slug>[\w-]+)/?$', PollDetailView.as_view()),
54-
]
55-
56-
57-
What this all means
58-
===================
59-
60-
In the ``PollsApphook`` class, we have done several key things:
61-
62-
* The ``app_name`` attribute gives the system a way to refer to the apphook - see :ref:`multi_apphook` for details
63-
on why this matters.
64-
* ``name`` is a human-readable name for the admin user.
65-
* The ``get_urls()`` method is what actually hooks the application in, returning a list of URL configurations that will
66-
be made active wherever the apphook is used.
42+
* ``app_name`` attribute gives the system a unique way to refer to the apphook - see
43+
:ref:`multi_apphook` for details on why this matters.
44+
* ``name`` is a human-readable name, and will be displayed to the admin user.
45+
* ``get_urls()`` method is what actually hooks the application in, returning a
46+
list of URL configurations that will be made active wherever the apphook is used.
6747

6848
**Restart the runserver**. This is necessary because we have created a new file containing Python
6949
code that won't be loaded until the server restarts. You only have to do this the first time the
@@ -80,7 +60,7 @@ Now we need to create a new page, and attach the Polls application to it through
8060

8161
Create and save a new page, then publish it.
8262

83-
.. note:: Your apphook won't work until the page has been published.
63+
.. note:: Your apphook won't work until the page has been published.
8464

8565
In its *Advanced settings*, choose "Polls Application" from the *Application* menu, and save once
8666
more.
@@ -94,9 +74,11 @@ Refresh the page, and you'll find that the Polls application is now available
9474
directly from the new django CMS page.
9575

9676
You can now remove the mention of the Polls application (``url(r'^polls/', include('polls.urls',
97-
namespace='polls'))``) from your project's ``urls.py`` - it's no longer even required there.
77+
namespace='polls'))``) from your project's ``urls.py`` - it's no longer even required there,
78+
because we reach the polls via the apphook instead. If you leave it there, then you'll receive a
79+
warning in the logs::
9880

99-
Later, we'll install a django-CMS-compatible :ref:`third-party application <third_party>`.
81+
URL namespace 'polls' isn't unique. You may not be able to reverse all URLs in this namespace.
10082

10183
.. important::
10284

0 commit comments

Comments
 (0)
0