djangosnippets.org: Latest snippets tagged with 'urlpatterns'http://djangosnippets.org/tags/urlpatterns/2018-04-06T15:42:58.325677-05:00Dynamic generate urlpatterns for django 2
2018-04-06T15:42:58.325677-05:00dimkoughttp://djangosnippets.org/snippets/10645/<p>Create dynamic urlpatterns for classed based views</p>
Freely redistributableExpand(flatten) url patterns
2012-11-21T18:06:52.109140-06:00grillermohttp://djangosnippets.org/snippets/2851/<p>This is a small function for those time when you want a list of all your urls, expanding included urls, so in the end is like all your urls are in one module. This function recursively does it, so it doesnt matter how nested the includes are in the end …</p>
Freely redistributableGeneric object_detail view with multiple named URL filters
2011-12-14T12:43:08.040407-06:00cottonhttp://djangosnippets.org/snippets/2627/<p>This snippet is greatly inspired by <a href="http://djangosnippets.org/users/jlorich/">@jlorich</a>'s useful <a href="http://djangosnippets.org/snippets/2436/">#2436</a>.</p>
<p>The main difference is that I wanted to choose the names of my URL params instead of being forced into naming them "value1", "value2", etc. When reversing the URL you have to remember that the kwargs aren't friendly. By …</p>
Freely redistributableDecorating URL includes
2011-08-25T19:45:06.038887-05:00cottonhttp://djangosnippets.org/snippets/2532/<p>Apply a decorator to every urlpattern and URLconf module returned by Django's include() method . This allows you use a decorator on any number of views without having to decorate each one individually. </p>
<p>The use case here is wrapping all of the Django Admin with a superuser decorator. This is …</p>
Freely redistributable@url decorator improvements
2009-08-06T16:19:07.120806-05:00davepeckhttp://djangosnippets.org/snippets/1671/<p>A slight modification (and, I think, improvement) of the URL decorator found in <a href="http://www.djangosnippets.org/snippets/395/">snippet 395</a>.</p>
<p>What's different between this snippet and 395?</p>
<ol>
<li>We use <code>django.conf.urls.defaults.url()</code> when adding patterns</li>
<li>We support arbitrary arguments to the <code>url()</code> method (like <code>name="foo"</code>)</li>
<li>We <em>do not</em> support multiple url patterns (this didn't seem …</li></ol>
Freely redistributableDebug view: show available named URL patterns
2009-04-13T03:36:43.846586-05:00simonhttp://djangosnippets.org/snippets/1434/<p>Hook the show_url_patterns view function in to your URLconf to get a page which simply lists all of the named URL patterns in your system - useful for if your template developers need a quick reference as to what patterns they can use in the {% url %} tag.</p>
Freely redistributableCheap direct_to_tempalte patterns
2008-11-14T16:47:28.117951-06:00jjdelchttp://djangosnippets.org/snippets/1190/<p>Django cheap-pages</p>
<p>Methods to use when you just want to use the Django dispatcher and there will be no extra business logic in your pages.</p>
<p>In some cases flatpages is too flat, and store templates in DB is too much hassle</p>
<pre><code> >>> url(^name/$,
... direct_to_template,
... {'template': 'name.html'},
... name='name') …</code></pre>
Freely redistributableDecorating urlpatterns
2008-01-01T19:33:41.709989-06:00miracle2khttp://djangosnippets.org/snippets/532/<p>One thing I wanted for a while was the ability to basically apply something like @login_required to a bunch of urlpatterns in one go, instead of having to decorate each and every view manually.</p>
<p>In this example, the latter two views will always raise a 404.</p>
Freely redistributable@url decorator - getting rid of urlpatterns
2007-08-29T11:29:38.584647-05:00southern_sunhttp://djangosnippets.org/snippets/395/<p>The rationale behind this decorator is described in django-users google group.</p>
<p>Usage:</p>
<pre><code>=== urls.py ===
urlpatterns = patterns('',
(r'^', include('apps.app1.views')),
(r'^app2', include('apps.app2.views')),
)
=== apps/app1/views/__init__.py ===
@url(r'^index/$')
def index(request):
...
@url(r'^news/$')
def news(request):
...
urlpatterns += include_urlpatterns(r'^members', 'apps.app1.views.members')
=== apps/app1/views/members.py ===
@url(r'^profile/$)
def profile(request):
....
@url(r'^secure/$)
def secure(request):
...
@url(r'^path1/$', …</code></pre>
Freely redistributable