Nucl3ic Nucl3ic - 1 year ago 161
Python Question

Serve entirely static (documentation) website from Django url in Django 1.10

I am using mkdocs for a wiki documentation site that serves markdown tutorials and general information files created by various people. mkdocs ouputs an entirely static site in a

directory. Is there anyway to serve this site in django 1.10? I know you used to be able to do something like this:

url(r'^docs/wiki/', 'django.views.static.serve', {'document_root': base.DOCS_ROOT, 'path': 'index.html'}),
url(r'^docs/wiki/(?P<path>.*)$', 'django.views.static.serve', {'document_root': base.DOCS_ROOT}),

but that no longer works in Django 1.10 because views must be callable lists or tuples.

I would prefer to not serve this out of templates because the assets for the website in order not to split the assets mkdocs creates into the django static directory from the html files it creates that would presumably be in templates.

error given if attempted to run server:

raise TypeError('view must be a callable or a list/tuple in the case of include().')

Any simple way to do this with urls?

Answer Source

Django 1.10 no longer allows you to specify views as a string (e.g. 'django.views.static.serve') in your URL patterns.

The solution is to update your to include the view callable. This means that you have to import the view in your If your URL patterns don't have names, then now is a good time to add one, because reversing with the dotted python path also no longer works.

Update your code like this :

from django.views.static import serve
from django.conf.urls import url, patterns

urlpatterns = [

  url(r'^docs/wiki/',serve, {'document_root': base.DOCS_ROOT, 'path': 'index.html'},name = "wiki1"),
  url(r'^docs/wiki/(?P<path>.*)$', serve, {'document_root': base.DOCS_ROOT},name = "wiki2"),
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download