django_markdown
django_markdown copied to clipboard
TypeError : 'QueryDict' object is not callable on markdown preview
When I try to preview my markdown I got an error 500 with this response.
`Environment:
Request Method: GET Request URL: http://localhost:8000/markdown/preview/
Django Version: 1.8.4 Python Version: 3.4.3 Installed Applications: ('django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'blog', 'django_markdown') Installed Middleware: ('django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.security.SecurityMiddleware')
Traceback: File "/usr/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response
-
File "/usr/lib/python3.4/site-packages/django_markdown/views.py" in previewresponse = wrapped_callback(request, _callback_args, *_callback_kwargs)
-
content=request.REQUEST.get('data','No posted content'),
Exception Type: TypeError at /markdown/preview/ Exception Value: 'QueryDict' object is not callable`
Fix the views.py inside django_markdown folder at line 20:
return render(request,
settings.MARKDOWN_PREVIEW_TEMPLATE,
dict(content=request.GET.get('data', '## No content posted ##'),
css=settings.MARKDOWN_STYLE
))
This problem was caused by an outdated method:
request.REQUEST.get('data', 'No content posted')
In django v3.1, there is no REQUEST.get, use this instead request.GET.get. Furthermore, request.GET returns dictionary like object that alike QuerryDict
Please point out if I mistook something, any advice would be greatly appreciated !
@Twiinner , thank you. This tutorial I'm watching is old and the guy is using an older version of django. Your answer saved me.