Django. Removal of text from Text Field to template



  • I'm green in Django.

    I want to make the text entry field a user. The text is then retained in the OBD system. And we'll get the template. Problem that the text will be kept in a complete fashion without a formatting (although the row is moved, I am not saying it, etc.) and, accordingly, it will be a complete text.

    Show me. How do you do that? How do you take into account the transposition of the line made by the user when entering the template?

    Manipulation from htmlhtml in the Text Field and filter will not be safe; BBcode is an option, but then the question arises as to how to provide a forum form for the introduction of text with formatting buttons?



  • The simplest is to use any expanded text editor for django. For example, http://github.com/django-ckeditor/django-ckeditor ♪ He has a built-in field that will help you filter unnecessary html flows. Plus, there's a html editor in the database. In general, it's all written in the file.

    The second option is to use the package. https://github.com/mozilla/bleach and manually filter the currents. It can also be used with a supplement like https://pythonhosted.org/Markdown/ ♪ From the minus here, you'll have to write your own processor for these very gatees. Example of code:

    # templatetags/comments.py
    

    -- coding: utf-8 --

    import bleach
    import markdown

    def markdown_comment(value):
    return bleach.clean(
    markdown.markdown(value, extensions=['nl2br']),
    strip=True,
    tags=['strong', 'p', 'blockquote', 'br'])

    @register.filter
    def comment_markdown(value):
    return mark_safe(markdown_comment(value))

    And then use it as {{ value|comment_markdown }}




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2