Skip to content

Commit 5b5108b

Browse files
committed
adding first code example page
1 parent 68080c4 commit 5b5108b

File tree

1 file changed

+60
-11
lines changed

1 file changed

+60
-11
lines changed

content/pages/examples/django/django-urls-path.markdown

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ meta: Python code examples for the path function within the django.urls module o
88

99

1010
# django.urls.path Examples
11-
The [path](https://github.com/django/django/blob/master/django/urls/conf.py) function
12-
is contained with the
13-
[django.urls](https://github.com/django/django/tree/master/django/urls) module within
14-
the [Django project](/django.html) code base.
11+
The [path](https://github.com/django/django/blob/master/django/urls/conf.py)
12+
function is contained with the
13+
[django.urls](https://github.com/django/django/tree/master/django/urls)
14+
module within the [Django project](/django.html) code base.
15+
16+
`path` is used for routing URLs to the appropriate view functions within
17+
a Django application using the
18+
[URL dispatcher](https://docs.djangoproject.com/en/dev/topics/http/urls/).
1519

1620

1721
## Example 1 from gadget-board
@@ -23,7 +27,7 @@ the [Django project](/django.html) code base.
2327
[**gadget-board/web/gadget_board_backend/urls.py**](https://github.com/mik4el/gadget-board/blob/master/web/gadget_board_backend/urls.py)
2428

2529
```python
26-
from django.conf.urls import url, include
30+
~~from django.conf.urls import url, include
2731
from django.contrib import admin
2832
from rest_framework_nested import routers
2933
from rest_framework_jwt.views import obtain_jwt_token
@@ -40,13 +44,58 @@ gadgets_router.register(r'data', GadgetDataViewSet, base_name='gadgets-data')
4044

4145
urlpatterns = [
4246
~~ url(r'^backend/admin/', admin.site.urls),
43-
url(r'^backend/api-auth/', include('rest_framework.urls', namespace='rest_framework')),
44-
url(r'^backend/api-token-auth/', obtain_jwt_token),
45-
url(r'^backend/api-token-refresh/', refresh_jwt_token),
46-
url(r'^backend/api/v1/', include(router.urls)),
47-
url(r'^backend/api/v1/', include(gadgets_router.urls)),
47+
~~ url(r'^backend/api-auth/', include('rest_framework.urls', namespace='rest_framework')),
48+
~~ url(r'^backend/api-token-auth/', obtain_jwt_token),
49+
~~ url(r'^backend/api-token-refresh/', refresh_jwt_token),
50+
~~ url(r'^backend/api/v1/', include(router.urls)),
51+
~~ url(r'^backend/api/v1/', include(gadgets_router.urls)),
4852
]
4953
```
5054

5155

52-
## Example 2 from gadget-board
56+
## Example 2 from ORGAN-IZE/register
57+
[register](https://github.com/ORGAN-IZE/register) is a [Django](/django.html),
58+
[Bootstrap](/bootstrap.html), [PostgreSQL](/postgresql.html) project that is
59+
open source under the
60+
[GNU General Public License v3.0](https://github.com/ORGAN-IZE/register/blob/master/LICENSE).
61+
This web application makes it easier for people to register as organ donors.
62+
You can see the application live at
63+
[https://register.organize.org/](https://register.organize.org/).
64+
65+
[**ORGAN-IZE/register/urls.py**](https://github.com/ORGAN-IZE/register/blob/master/urls.py)
66+
67+
```python
68+
from __future__ import unicode_literals
69+
70+
~~import django.conf
71+
~~import django.conf.urls
72+
import django.views.generic
73+
import django.contrib.auth.urls
74+
import django.conf
75+
import django.conf.urls.static
76+
import django.conf.urls.i18n
77+
import django.contrib.admin
78+
from django.contrib.auth import views
79+
80+
81+
urlpatterns = [
82+
~~ django.conf.urls.url(r'^i18n/', django.conf.urls.include('django.conf.urls.i18n')),
83+
~~ django.conf.urls.url(r'^robots.txt$',
84+
~~ django.views.generic.TemplateView.as_view(template_name='robots.txt')),
85+
~~ django.conf.urls.url(r'^', django.conf.urls.include('registration.urls')),
86+
~~ django.conf.urls.url(r'^brand/', django.conf.urls.include('cobrand.urls')),
87+
~~ django.conf.urls.url(r'^admin/', django.conf.urls.include(django.contrib.admin.site.urls)),
88+
89+
# override the admin password reset flow to use the normal site password
90+
# reset flow
91+
~~ django.conf.urls.url(r'^password_reset/$', views.password_reset,
92+
~~ name='admin_password_reset'),
93+
~~ django.conf.urls.url(r'^login/$',
94+
~~ django.views.generic.RedirectView.as_view(url='/admin/login')),
95+
~~ django.conf.urls.url(r'^', django.conf.urls.include('accountsplus.urls')),
96+
~~ django.conf.urls.url(r'^widget/', django.conf.urls.include('widget.urls')),
97+
]
98+
99+
## ... the source file continues here without any further examples
100+
```
101+

0 commit comments

Comments
 (0)