Reputation: 3697
I have following code structure in Django.
├── docs
│ └── _build
│ ├── doctrees
│ └── html
│ └── index.html
│
├── localcoinswap
├── scripts
├── _static
├── _templates
├── tests
└── manage.py
Here the docs
folder contains static html files. i.e index.html
Here are some questions regarding to problem:
The docs
folder's html should be served as url <domain>/docs/index.html
in Django
project. How to achieve this
It should be restricted to User's who have is_staff
attribute True
.
What urlpattern
should I use and Which View
is useful to serve those static files (Admin restricted)?
Thank you in advance!
Upvotes: 2
Views: 86
Reputation: 2547
Add the base directory for your docs in TEMPLATES
setting in settings.py
.
TEMPLATES = [
{
...
'DIRS': [os.path.join(BASE_DIR, '_templates'), "add your base directory here"],
...
}
]
In your urls.py
, serve the files using TemplateView
. To further restrict the url to only the staff users, you can wrap the view in staff_member_required
decorator.
from django.contrib.admin.views.decorators import staff_member_required
...
urlpatterns += [url(r'^docs/index\.html$', staff_member_required(TemplateView.as_view(template_name='index.html')), name="index"),]
Make sure the file names for your templates and doc templates don't clash, else the first one evaluated according to the DIR
list will always be considered.
Upvotes: 1