Custom root urls

Why?

Devilry comes with a default URL-route config for production. You may want to add to this if you need to install other Django apps on the Devilry server.

Create an URL config file

First, create a url file in the same directory as your devilry_prod_settings.py. We will call the file devilry_prod_urls.py for this example, but you can name it anything you like as long as it is a valid python module name (english letters, no spaces, end with .py).

The file should look like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
from django.conf.urls.defaults import patterns
from django.conf.urls.defaults import url
from django.conf.urls.defaults import include
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

from devilry.apps.core import pluginloader
from devilry_settings.default_urls import devilry_urls


urlpatterns = patterns('',
    # Custom urls
    # Example:
    # url(r'^trix/', include('trix.urls')),

    # Add the default Devilry urls
    *devilry_urls
) + staticfiles_urlpatterns()

# Must be after url-loading to allow plugins to use reverse()
pluginloader.autodiscover()

Add your custom URLs as shown in the example on line 13.

Make devilry_prod_settings.py use your custom urls

Update your devilry_prod_settings.py with:

ROOT_URLCONF = 'devilry_prod_urls'

Use a custom Frontpage?

You can easily create serve your own Django app as the frontpage instead of the default Devilry frontpage. Django uses the first matched url-config, so we can override the match for / and replace it with our own view.

Here is an example that sets up urls for the Trix-project on /trix/, and uses a Django redirect view to redirect the frontpage to that URL. We also setup the default Devilry frontpage at /devilry/:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from django.conf.urls.defaults import patterns
from django.conf.urls.defaults import url
from django.conf.urls.defaults import include
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.views.generic.base import RedirectView

from devilry.apps.core import pluginloader
from devilry_settings.default_urls import devilry_urls
from devilry_frontpage.views import frontpage


urlpatterns = patterns('',
    # Custom urls
    url(r'^trix/', include('trix.urls')),

    # Move the default Devilry frontpage to /devilry, and redirect to Trix instead.
    (r'^devilry/$', frontpage),
    (r'^$', RedirectView.as_view(permanent=False, url="/trix/", query_string=True)),


    # Add the default Devilry urls
    *devilry_urls
) + staticfiles_urlpatterns()

# Must be after url-loading to allow plugins to use reverse()
pluginloader.autodiscover()

Note

Tou do not have to redirect from the frontpage, you can just as easily use a Django view that renders your view at / without a redirect.