django-markdownx icon indicating copy to clipboard operation
django-markdownx copied to clipboard

Simple optimization inside views.py

Open Nigel2392 opened this issue 3 years ago • 0 comments

Instead of importing the markdownify function every time the view's POST method is called, instead import it at global scope.

Example:

markdownify_func = import_string(MARKDOWNX_MARKDOWNIFY_FUNCTION)

class MarkdownifyView(View):
    """
    Conversion of Markdown to HTML.
    """

    def post(self, request, *args, **kwargs):
        """
        Handling of the conversion from Markdown to HTML using the conversion
        function in settings under ``MARKDOWNX_MARKDOWNIFY_FUNCTION``.

        :param request: HTTP request.
        :param args: Default Django POST arguments.
        :param kwargs: Default Django POST keyword arguments.
        :return: HTTP response
        :rtype: django.http.HttpResponse
        """
        # Function used to be imported every POST request. 
        return HttpResponse(markdownify_func(request.POST['content']))

Nigel2392 avatar Sep 24 '22 06:09 Nigel2392