Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live API docs (#4755) makes markdown dependency non-optional #4941

Closed
carltongibson opened this issue Mar 6, 2017 · 13 comments · Fixed by #4943
Closed

Live API docs (#4755) makes markdown dependency non-optional #4941

carltongibson opened this issue Mar 6, 2017 · 13 comments · Fixed by #4943

Comments

@carltongibson
Copy link
Collaborator

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
)

https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/templatetags/rest_framework.py#L12-L16

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 carltongibson/django-filter#658

Markdown either needs to be declared required or a work around is needed.

@tomchristie
Copy link
Member

👍 blocker for 3.6

@tomchristie tomchristie mentioned this issue Mar 7, 2017
15 tasks
@tomchristie
Copy link
Member

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.

@intgr
Copy link
Contributor

intgr commented Mar 9, 2017

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'

@tomchristie
Copy link
Member

Thanks @intgr - I'll take a look at addressing that now.

@micheledallatorre
Copy link

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.

@tomchristie
Copy link
Member

@micheledallatorre - Should be resolved as of just now. Upgrade to 3.6.1 (Or install the markdown library and stick with 3.6.0)

@micheledallatorre
Copy link

micheledallatorre commented Mar 9, 2017

Thank you.
Running pip install django-markdown solved the issue.

@sakshij
Copy link

sakshij commented Sep 12, 2017

@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'

@Dziugas
Copy link

Dziugas commented Mar 6, 2018

@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'

@carltongibson
Copy link
Collaborator Author

What Django version are you running?

@Dziugas
Copy link

Dziugas commented Mar 6, 2018

@carltongibson I'm using Django 1.9.0

@carltongibson
Copy link
Collaborator Author

Django 1.9 is End of Life and no-longer supported. You should upgrade to Django 1.11 LTS or Django 2.0

@Dziugas
Copy link

Dziugas commented Mar 6, 2018

thanks, @carltongibson, I installed Django 2.0, it now works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants