@@ -34,36 +34,16 @@ This is a very basic example of an apphook for a django CMS application:
34
34
name = _(" Polls Application" )
35
35
36
36
def get_urls (self , page = None , language = None , ** kwargs ):
37
- return [" polls.urls" ]
37
+ return [" polls.urls" ] ]
38
38
39
39
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:
42
41
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.
67
47
68
48
**Restart the runserver **. This is necessary because we have created a new file containing Python
69
49
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
80
60
81
61
Create and save a new page, then publish it.
82
62
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.
84
64
85
65
In its *Advanced settings *, choose "Polls Application" from the *Application * menu, and save once
86
66
more.
@@ -94,9 +74,11 @@ Refresh the page, and you'll find that the Polls application is now available
94
74
directly from the new django CMS page.
95
75
96
76
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::
98
80
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 .
100
82
101
83
.. important ::
102
84
0 commit comments