klen / django_markdown

Django markdown support and wysiwig
GNU Lesser General Public License v3.0
389 stars 143 forks source link

TypeError : 'QueryDict' object is not callable on markdown preview #50

Open DarkRedman opened 8 years ago

DarkRedman commented 8 years ago

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

  1. response = wrapped_callback(request, _callback_args, *_callback_kwargs) File "/usr/lib/python3.4/site-packages/django_markdown/views.py" in preview
  2. content=request.REQUEST.get('data','No posted content'),

Exception Type: TypeError at /markdown/preview/ Exception Value: 'QueryDict' object is not callable`

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/26309679-typeerror-querydict-object-is-not-callable-on-markdown-preview?utm_campaign=plugin&utm_content=tracker%2F332251&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F332251&utm_medium=issues&utm_source=github).
Twiinner commented 3 years ago

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 !

dapoadedire commented 2 years ago

@Twiinner , thank you. This tutorial I'm watching is old and the guy is using an older version of django. Your answer saved me.