Skip to content

Commit

Permalink
Merge pull request #334 from vartagg/middleware-name
Browse files Browse the repository at this point in the history
SILKY_MIDDLEWARE_CLASS option
  • Loading branch information
mbeacom authored Mar 12, 2019
2 parents 1d2968c + ef7d2f7 commit df15c51
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ INSTALLED_APPS = (

**Note:** If you are using `django.middleware.gzip.GZipMiddleware`, place that **before** `silk.middleware.SilkyMiddleware`, otherwise you will get an encoding error.

If you want to use custom middleware, for example you developed the subclass of `silk.middleware.SilkyMiddleware`, so you can use this combination of settings:

```python
# Specify the path where is the custom middleware placed
SILKY_MIDDLEWARE_CLASS = 'path.to.your.middleware.MyCustomSilkyMiddleware'

# Use this variable in list of middleware
MIDDLEWARE = [
...
SILKY_MIDDLEWARE_CLASS,
...
]
```

To enable access to the user interface add the following to your `urls.py`:

```python
Expand Down
3 changes: 2 additions & 1 deletion silk/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class SilkyConfig(six.with_metaclass(Singleton, object)):
'SILKY_INTERCEPT_PERCENT': 100,
'SILKY_INTERCEPT_FUNC': None,
'SILKY_PYTHON_PROFILER': False,
'SILKY_STORAGE_CLASS': 'silk.storage.ProfilerResultStorage'
'SILKY_STORAGE_CLASS': 'silk.storage.ProfilerResultStorage',
'SILKY_MIDDLEWARE_CLASS': 'silk.middleware.SilkyMiddleware'
}

def _setup(self):
Expand Down
2 changes: 1 addition & 1 deletion silk/profiling/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def _silk_installed(self):
middlewares = getattr(settings, 'MIDDLEWARE', [])
if not middlewares:
middlewares = []
middleware_installed = 'silk.middleware.SilkyMiddleware' in middlewares
middleware_installed = SilkyConfig().SILKY_MIDDLEWARE_CLASS in middlewares
return app_installed and middleware_installed

def _should_profile(self):
Expand Down

0 comments on commit df15c51

Please sign in to comment.