rest_framework.templatetags.rest_framework is non-conditionally importing markdown.
from markdown.extensions.fenced_code import FencedBlockPreprocessor
from rest_framework.compat import (
NoReverseMatch, markdown, reverse, template_render
)
As per the compat import markdown has previously been an optional dependency. It's still listed as an optional requirement
Without markdown installed, the template tags can no longer be imported. cf https://github.com/carltongibson/django-filter/pull/658
Markdown either needs to be declared required or a work around is needed.
馃憤 blocker for 3.6
We don't really need that extension - it was more of a hangover from first pass at building the API docs. I've removed it for now - if we do add any markdown extensions to it we can make sure to do so in an optional dependency manner.
The "fix" for this issue was insufficient. Note the line in templatetags/rest_framework.py:
from rest_framework.compat import (
NoReverseMatch, markdown, pygments_highlight, reverse, template_render
)
This unconditionally tries to import the name markdown, however, compat.py has this code:
# Markdown is optional
try:
import markdown
...
except ImportError:
apply_markdown = None
The name markdown that templatetags attempts to import won't be defined if import markdown fails -- only apply_markdown is. Therefore it still causes the exception on import: django.template.library.InvalidTemplateLibrary: Invalid template library specified. ImportError raised when trying to load 'rest_framework.templatetags.rest_framework': cannot import name 'markdown'
Thanks @intgr - I'll take a look at addressing that now.
Hello,
I tried following the quickstart (http://www.django-rest-framework.org/tutorial/quickstart/) but I get the following error.
InvalidTemplateLibrary at /
Invalid template library specified. ImportError raised when trying to load 'rest_framework.templatetags.rest_framework': cannot import name markdown
How to fix that?
Thanks.
@micheledallatorre - Should be resolved as of just now. Upgrade to 3.6.1 (Or install the markdown library and stick with 3.6.0)
Thank you.
Running pip install django-markdown solved the issue.
@tomchristie I am on 3.6.2 and still getting this error. When I added django markdown to requirements, this got resolved but I started getting a different error when trying to run celery -
django.core.management.base.CommandError: Unknown command: 'syncdb'
@tomchristie I am on python 3.6.1, have markdown installed and still get the following error:
Invalid template library specified. ImportError raised when trying to load 'rest_framework.templatetags.rest_framework': No module named 'django.urls'
What Django version are you running?
@carltongibson I'm using Django 1.9.0
Django 1.9 is End of Life and no-longer supported. You should upgrade to Django 1.11 LTS or Django 2.0
thanks, @carltongibson, I installed Django 2.0, it now works.
Most helpful comment
Thank you.
Running
pip install django-markdownsolved the issue.