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


Release history Release notifications

History Node

0.2.1

This version
History Node

0.2

History Node

0.1

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
django-dictpatterns-0.2.tar.gz (3.3 kB) Copy SHA256 hash SHA256 Source None Apr 6, 2014

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page