Giter Site home page Giter Site logo

Template about django-markdownx HOT 8 CLOSED

neutronx avatar neutronx commented on June 4, 2024
Template

from django-markdownx.

Comments (8)

sujan-sube avatar sujan-sube commented on June 4, 2024 3

Hi StudentDwid,

I was able to get it working by rendering the markdown in views.py then passing it to templates. I wanted to render the text in the object post.text then pass it to templates to render blog/post_list.html.This is how it looks:

views.py:

from markdownx.utils import markdownify

posts = Post.objects.filter(published_date__lte=timezone.now())
def post_list(request):
    for post in posts:
        post.text = markdownify(post.text)
    return render(request, 'blog/post_list.html', {'posts': posts})

post_list.html:

        <div class="post">
            <h1>
                <a href="{% url 'post_detail' pk=post.pk %}">{{ post.title }}</a>
            </h1>
            <p>{{ post.text|safe }}</p>
        </div>

from django-markdownx.

StudentDawid avatar StudentDawid commented on June 4, 2024

It`s work, Thank you 😄

from django-markdownx.

sujan-sube avatar sujan-sube commented on June 4, 2024

No problem, glad its working for you. 😃

from django-markdownx.

oskarko avatar oskarko commented on June 4, 2024

this doesn't work for me :(

from django-markdownx.

oskarko avatar oskarko commented on June 4, 2024

I have a paginator with this

class PostListView(ListView):
model = Post
paginate_by = 5
template_name = 'post_list.html'
queryset = Post.objects.filter(published_date__lte=timezone.now()).order_by('-published_date')

and I can't do markdownify(post.text)

from django-markdownx.

oskarko avatar oskarko commented on June 4, 2024

I got it!

class PostListView(ListView):
model = Post
paginate_by = 5
template_name = 'post_list.html'

change my query before returns

def get_queryset(self):
    posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('-published_date')
    for post in posts:
        post.text = markdownify(post.text)
    return posts

from django-markdownx.

StanleyDerLurch avatar StanleyDerLurch commented on June 4, 2024

Is there a solution for "unmarkdownify"?
I have an update_view and get the plain HTML text back on editing. It is not usable for other users

from django-markdownx.

0-afflatus avatar 0-afflatus commented on June 4, 2024

sujan-sube this works for me - I'm new to markdownx as of 2 days ago. This example helped me get things working the way I like. May I suggest adding it to the docs? I think it deals with #74 too.

from django-markdownx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.