Skip to content

Commit 8c421fd

Browse files
author
Emmanouil Konstantinidis
committed
Settings - Hidden
1 parent a3b5cec commit 8c421fd

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ Finally include the `rest_framework_docs` urls in your `urls.py`:
3838
url(r'^docs/', include('rest_framework_docs.urls')),
3939
]
4040

41+
### Settings
42+
43+
REST_FRAMEWORK_DOCS = {
44+
'HIDDEN': True # Default: False
45+
}
46+
4147
### Roadmap
4248

4349
- [ ] Support Python 2 & Python 3

rest_framework_docs/settings.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from django.conf import settings
2+
3+
4+
class DRFSettings(object):
5+
6+
def __init__(self):
7+
self.drf_settings = {
8+
"HIDDEN": self.get_setting("HIDDEN") or False
9+
}
10+
11+
def get_setting(self, name):
12+
try:
13+
return settings.REST_FRAMEWORK_DOCS[name]
14+
except:
15+
return None
16+
17+
@property
18+
def settings(self):
19+
return self.drf_settings

rest_framework_docs/views.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
from django.http import Http404
12
from django.views.generic.base import TemplateView
23
from rest_framework_docs.api_docs import ApiDocumentation
4+
from rest_framework_docs.settings import DRFSettings
35

46

57
class DRFDocsView(TemplateView):
68

79
template_name = "rest_framework_docs/home.html"
810

911
def get_context_data(self, **kwargs):
12+
settings = DRFSettings().settings
13+
if settings["HIDDEN"]:
14+
raise Http404("Django Rest Framework Docs are hidden. Check you settings.")
15+
1016
context = super(DRFDocsView, self).get_context_data(**kwargs)
1117
docs = ApiDocumentation()
1218
context['endpoints'] = docs.get_endpoints()

0 commit comments

Comments
 (0)