Skip to content

Commit 209b22f

Browse files
committed
fix issue with urls and path examples
1 parent 5b5108b commit 209b22f

File tree

4 files changed

+158
-80
lines changed

4 files changed

+158
-80
lines changed
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
title: django.conf.urls.url Examples
2+
category: page
3+
slug: django-conf-urls-url-examples
4+
sortorder: 5001
5+
toc: False
6+
sidebartitle: django.conf.urls.url Examples
7+
meta: Python code examples for the url function within the django.conf.urls module of the Django project.
8+
9+
10+
# django.conf.urls.url Examples
11+
The [url](https://github.com/django/django/blob/master/django/conf/urls/__init__.py)
12+
function is contained with the
13+
[django.conf.urls](https://github.com/django/django/tree/master/django/conf/urls)
14+
module within the [Django project](/django.html) code base.
15+
16+
`url` relies on Django's
17+
[URL dispatcher](https://docs.djangoproject.com/en/dev/topics/http/urls/)
18+
functionality and is used for mapping URLs to matching view functions within
19+
a Django app.
20+
21+
22+
## Example 1 from gadget-board
23+
[gadget-board](https://github.com/mik4el/gadget-board) is a [Django](/django.html),
24+
[Django REST Framework (DRF)](/django-rest-framework-drf.html) and
25+
[Angular](/angular.html) web application that is open source under the
26+
[Apache2 license](https://github.com/mik4el/gadget-board/blob/master/LICENSE).
27+
28+
[**gadget-board/web/gadget_board_backend/urls.py**](https://github.com/mik4el/gadget-board/blob/master/web/gadget_board_backend/urls.py)
29+
30+
```python
31+
from django.contrib import admin
32+
~~from django.conf.urls import url, include
33+
from rest_framework_nested import routers
34+
from rest_framework_jwt.views import obtain_jwt_token
35+
from rest_framework_jwt.views import refresh_jwt_token
36+
37+
from authentication.views import AccountViewSet
38+
from gadgets.views import GadgetViewSet, GadgetDataViewSet
39+
40+
router = routers.SimpleRouter()
41+
router.register(r'accounts', AccountViewSet)
42+
router.register(r'gadgets', GadgetViewSet)
43+
gadgets_router = routers.NestedSimpleRouter(router, r'gadgets', lookup='gadget')
44+
gadgets_router.register(r'data', GadgetDataViewSet, base_name='gadgets-data')
45+
46+
urlpatterns = [
47+
~~ url(r'^backend/admin/', admin.site.urls),
48+
~~ url(r'^backend/api-auth/', include('rest_framework.urls', namespace='rest_framework')),
49+
~~ url(r'^backend/api-token-auth/', obtain_jwt_token),
50+
~~ url(r'^backend/api-token-refresh/', refresh_jwt_token),
51+
~~ url(r'^backend/api/v1/', include(router.urls)),
52+
~~ url(r'^backend/api/v1/', include(gadgets_router.urls)),
53+
]
54+
```
55+
56+
57+
## Example 2 from ORGAN-IZE/register
58+
[register](https://github.com/ORGAN-IZE/register) is a [Django](/django.html),
59+
[Bootstrap](/bootstrap.html), [PostgreSQL](/postgresql.html) project that is
60+
open source under the
61+
[GNU General Public License v3.0](https://github.com/ORGAN-IZE/register/blob/master/LICENSE).
62+
This web application makes it easier for people to register as organ donors.
63+
You can see the application live at
64+
[https://register.organize.org/](https://register.organize.org/).
65+
66+
[**ORGAN-IZE/register/urls.py**](https://github.com/ORGAN-IZE/register/blob/master/urls.py)
67+
68+
```python
69+
from __future__ import unicode_literals
70+
71+
~~import django.conf
72+
~~import django.conf.urls
73+
import django.views.generic
74+
import django.contrib.auth.urls
75+
import django.conf
76+
import django.conf.urls.static
77+
import django.conf.urls.i18n
78+
import django.contrib.admin
79+
from django.contrib.auth import views
80+
81+
82+
urlpatterns = [
83+
~~ django.conf.urls.url(r'^i18n/', django.conf.urls.include('django.conf.urls.i18n')),
84+
~~ django.conf.urls.url(r'^robots.txt$',
85+
~~ django.views.generic.TemplateView.as_view(template_name='robots.txt')),
86+
~~ django.conf.urls.url(r'^', django.conf.urls.include('registration.urls')),
87+
~~ django.conf.urls.url(r'^brand/', django.conf.urls.include('cobrand.urls')),
88+
~~ django.conf.urls.url(r'^admin/', django.conf.urls.include(django.contrib.admin.site.urls)),
89+
90+
# override the admin password reset flow to use the normal site password
91+
# reset flow
92+
~~ django.conf.urls.url(r'^password_reset/$', views.password_reset,
93+
~~ name='admin_password_reset'),
94+
~~ django.conf.urls.url(r'^login/$',
95+
~~ django.views.generic.RedirectView.as_view(url='/admin/login')),
96+
~~ django.conf.urls.url(r'^', django.conf.urls.include('accountsplus.urls')),
97+
~~ django.conf.urls.url(r'^widget/', django.conf.urls.include('widget.urls')),
98+
]
99+
100+
## ... the source file continues here without any further examples
101+
```
102+
103+
104+
## Example 3 from django-allauth
105+
[django-allauth](https://github.com/pennersr/django-allauth)
106+
([project website](https://www.intenct.nl/projects/django-allauth/)) is a
107+
[Django](/django.html) library for easily adding local and social authentication
108+
flows to Django projects. It is open source under the
109+
[MIT License](https://github.com/pennersr/django-allauth/blob/master/LICENSE).
110+
111+
[**django-allauth/allauth/account/urls.py**](https://github.com/pennersr/django-allauth/blob/master/allauth/account/urls.py)
112+
113+
```python
114+
from . import views
115+
116+
~~from django.conf.urls import url
117+
118+
119+
urlpatterns = [
120+
~~ url(r"^signup/$", views.signup, name="account_signup"),
121+
~~ url(r"^login/$", views.login, name="account_login"),
122+
~~ url(r"^logout/$", views.logout, name="account_logout"),
123+
124+
~~ url(r"^password/change/$", views.password_change,
125+
~~ name="account_change_password"),
126+
~~ url(r"^password/set/$", views.password_set, name="account_set_password"),
127+
128+
~~ url(r"^inactive/$", views.account_inactive, name="account_inactive"),
129+
130+
# E-mail
131+
~~ url(r"^email/$", views.email, name="account_email"),
132+
~~ url(r"^confirm-email/$", views.email_verification_sent,
133+
~~ name="account_email_verification_sent"),
134+
~~ url(r"^confirm-email/(?P<key>[-:\w]+)/$", views.confirm_email,
135+
~~ name="account_confirm_email"),
136+
137+
# password reset
138+
~~ url(r"^password/reset/$", views.password_reset,
139+
~~ name="account_reset_password"),
140+
~~ url(r"^password/reset/done/$", views.password_reset_done,
141+
~~ name="account_reset_password_done"),
142+
~~ url(r"^password/reset/key/(?P<uidb36>[0-9A-Za-z]+)-(?P<key>.+)/$",
143+
~~ views.password_reset_from_key,
144+
~~ name="account_reset_password_from_key"),
145+
~~ url(r"^password/reset/key/done/$", views.password_reset_from_key_done,
146+
~~ name="account_reset_password_from_key_done"),
147+
]
148+
```
149+

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

Lines changed: 1 addition & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -18,84 +18,6 @@ a Django application using the
1818
[URL dispatcher](https://docs.djangoproject.com/en/dev/topics/http/urls/).
1919

2020

21-
## Example 1 from gadget-board
22-
[gadget-board](https://github.com/mik4el/gadget-board) is a [Django](/django.html),
23-
[Django REST Framework (DRF)](/django-rest-framework-drf.html) and
24-
[Angular](/angular.html) web application that is open source under the
25-
[Apache2 license](https://github.com/mik4el/gadget-board/blob/master/LICENSE).
21+
## Example 1 from
2622

27-
[**gadget-board/web/gadget_board_backend/urls.py**](https://github.com/mik4el/gadget-board/blob/master/web/gadget_board_backend/urls.py)
28-
29-
```python
30-
~~from django.conf.urls import url, include
31-
from django.contrib import admin
32-
from rest_framework_nested import routers
33-
from rest_framework_jwt.views import obtain_jwt_token
34-
from rest_framework_jwt.views import refresh_jwt_token
35-
36-
from authentication.views import AccountViewSet
37-
from gadgets.views import GadgetViewSet, GadgetDataViewSet
38-
39-
router = routers.SimpleRouter()
40-
router.register(r'accounts', AccountViewSet)
41-
router.register(r'gadgets', GadgetViewSet)
42-
gadgets_router = routers.NestedSimpleRouter(router, r'gadgets', lookup='gadget')
43-
gadgets_router.register(r'data', GadgetDataViewSet, base_name='gadgets-data')
44-
45-
urlpatterns = [
46-
~~ url(r'^backend/admin/', admin.site.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)),
52-
]
53-
```
54-
55-
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-
```
10123

content/pages/meta/00-change-log.markdown

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ on GitHub.
1515

1616

1717
## 2019
18+
### June
19+
* Started new open source code examples series, beginning with
20+
[url](/django-conf-urls-url-examples.html)
21+
and [path](/django-urls-path-examples.html) functions.
22+
1823
### May
1924
* Added new [data visualization](/data-visualization.html),
2025
[web design](/web-design.html) and [pandas](/pandas.html) resources.

theme/templates/page.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
{% else %}
4444
{{ page.content }}
4545
{% endif %}
46-
{% if not page.sortorder == "5000" %}
46+
{% if page.sortorder[0:2] == "50" %}
47+
<hr>
48+
{% else %}
4749
{% include "choices/" + page.slug + ".html" %}
4850
{% endif %}
4951
{% include "email-for-book.html" %}

0 commit comments

Comments
 (0)