Skip to main content

This makes your application be able to write simple urlpatterns with dictionary for Django

Project description

In urls.py, you can write urlpatterns by using dictionary.

from django.conf.urls import include
from django.contrib import admin
admin.autodiscover()

from dictpatterns.urls import DictPatterns

UrlDictPatterns = DictPatterns(
    {
        r'^': ('testapp.views.home', 'home',
            {
                r'test/': ('testapp.views.test', 'test',
                    {
                        r'(?P<id>\d*)/': ('testapp.views.test_n', 'test_n',
                            {
                                r'd/': ('testapp.views.test_d', 'test_d')
                            }
                        )
                    }
                ),
                r'admin/': (include(admin.site.urls), 'admin')
            }
        )
    }
)

urlpatterns = UrlDictPatterns.to_patterns()

In template

Because of this format, you can trace the parent url of a page. You can display the parent url in template.

{% load dict_url_tools %}

Now :
<br>
{% this_url %}
<br>
Parent :
<br>
{% parent_url %}

Settings

Make sure of writing DictPatterns in your urls which is distinguished as ROOT_URLCONF. And distinguish the root of DictPatterns as ROOT_DICTPATTERNS_NAME in settings.py if you need. Default value is “UrlDictPatterns”.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-dictpatterns-0.2.tar.gz (3.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page