Question about URL Patterns

46 views
Skip to first unread message

Rachael Sewell

unread,
Dec 31, 2015, 3:52:35 PM12/31/15
to Mayan EDMS
Hello,

I'm new to the Django framework. I'm trying to figure out exactly where the url patterns are located. I see in mayan/settings/base.py that ROOT_URLCONF = 'mayan.urls'. In the mayan/url.py file I see that there are:

urlpatterns = patterns(
    '',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^docs/', include('rest_framework_swagger.urls')),
)


My question is, where are the patterns located for the rest of the URLs in the applications? For example, how are urls dispatched for /document? It appears to be working without having a urlpattern defined.

Rachael

Roberto Rosario

unread,
Dec 31, 2015, 4:07:55 PM12/31/15
to mayan...@googlegroups.com
App URLs are defined in each app's url.py file. The root urls.py then includes these app urls.py. This means having an include('') line for each app (as was done with the admin site and the API docs apps). To allow adding apps without having to edit this file by hand, Mayan subclasses Django's AppConfig (django.apps), and overrides the ready() method to do this dynamically: https://gitlab.com/mayan-edms/mayan-edms/blob/master/mayan/apps/common/apps.py#L52. The end result is that adding a 3rd party app in Mayan is a matter of just adding the app's name in the INSTALLED_APPS list in your settings.py file, the system takes care of all the integration.

--

---
You received this message because you are subscribed to the Google Groups "Mayan EDMS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mayan-edms+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rachael Sewell

unread,
Dec 31, 2015, 4:17:09 PM12/31/15
to mayan...@googlegroups.com
Roberto,

So the includes are all listed programmatically in the apps/common/apps.py file, correct? That is what I was missing! 

try:
            urlpatterns += url(
                r'^{}'.format(top_url),
                include(
                    '{}.urls'.format(self.name),
                    namespace=self.app_namespace or self.name
                )
            ),

Thanks,
Rachael

You received this message because you are subscribed to a topic in the Google Groups "Mayan EDMS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mayan-edms/I_CyLvlhqmI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mayan-edms+...@googlegroups.com.

Roberto Rosario

unread,
Dec 31, 2015, 4:24:01 PM12/31/15
to mayan...@googlegroups.com
That is correct. That block of code will execute once the app tells the system it is ready (models initialized, content type registered, etc). The front part of the URL will be the app's name by default, but can be overrided by the `app_url` property. For example, the `user_management` app registers its URLs under the `/account/`URL this way: https://gitlab.com/mayan-edms/mayan-edms/blob/master/mayan/apps/user_management/apps.py#L26
Reply all
Reply to author
Forward
0 new messages