Skip to content

Commit b227c78

Browse files
authored
Use lists in Django settings, use new url pattern (#210)
Since Django<1.11 lists are used for INSTALLED_APPS and MIDDLEWARE. Urls now also use a simplified path pattern, and django.urls.re_path shall be used for regex matches.
1 parent 0972744 commit b227c78

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

README.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ This will install [prometheus_client](https://github.com/prometheus/client_pytho
3636
In your settings.py:
3737

3838
```python
39-
INSTALLED_APPS = (
39+
INSTALLED_APPS = [
4040
...
4141
'django_prometheus',
4242
...
43-
)
43+
]
4444

45-
MIDDLEWARE = (
45+
MIDDLEWARE = [
4646
'django_prometheus.middleware.PrometheusBeforeMiddleware',
4747
# All your other middlewares go here, including the default
4848
# middlewares like SessionMiddleware, CommonMiddleware,
4949
# CsrfViewmiddleware, SecurityMiddleware, etc.
5050
'django_prometheus.middleware.PrometheusAfterMiddleware',
51-
)
51+
]
5252
```
5353

5454
In your urls.py:
@@ -176,13 +176,12 @@ First step is to inject prometheus' middlewares and to add
176176
django_prometheus in INSTALLED_APPS
177177

178178
```python
179-
MIDDLEWARE = (
180-
('django_prometheus.middleware.PrometheusBeforeMiddleware',) +
181-
MIDDLEWARE +
182-
('django_prometheus.middleware.PrometheusAfterMiddleware',)
183-
)
179+
MIDDLEWARE = \
180+
['django_prometheus.middleware.PrometheusBeforeMiddleware'] + \
181+
MIDDLEWARE + \
182+
['django_prometheus.middleware.PrometheusAfterMiddleware']
184183

185-
INSTALLED_APPS = INSTALLED_APPS + ('django_prometheus',)
184+
INSTALLED_APPS += ['django_prometheus']
186185
```
187186

188187
Second step is to create the /metrics end point, for that we need
@@ -195,7 +194,7 @@ from django.conf.urls import include, url
195194

196195
urlpatterns = []
197196

198-
urlpatterns.append(url('^prometheus/', include('django_prometheus.urls')))
197+
urlpatterns.append(url('prometheus/', include('django_prometheus.urls')))
199198
urlpatterns.append(url('', include('myapp.urls')))
200199
```
201200

@@ -216,4 +215,4 @@ This involves extending the classes defined in middleware.py.
216215
* Extend the Metrics class and override the `register_metric` method to add the application specific labels.
217216
* Extend middleware classes, set the metrics_cls class attribute to the the extended metric class and override the label_metric method to attach custom metrics.
218217

219-
See implementation example in [the test app](django_prometheus/tests/end2end/testapp/test_middleware_custom_labels.py#L19-L46)
218+
See implementation example in [the test app](django_prometheus/tests/end2end/testapp/test_middleware_custom_labels.py#L19-L46)

0 commit comments

Comments
 (0)