Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template #25

Closed
StudentDawid opened this issue Jul 4, 2016 · 8 comments
Closed

Template #25

StudentDawid opened this issue Jul 4, 2016 · 8 comments

Comments

@StudentDawid
Copy link

StudentDawid commented Jul 4, 2016

Hello, can you help me ? 馃槃
I don`t know how to show my markdown data on template.
I have something like

<h1>{{ post.title }}</h1>
<p>{{ post.text }}</p>
<p>{{ post.markdown }}</p>

and i see only

title
text
#text1 ![](/media/markdownx/ab3bfac7-7509-411a-96c8-11aebc20b873.jpg)

but i want compiled version (with image)
Could you explain how templates with markdownx work ? Or create some exaple with that ? 馃槃

@sujan-sube
Copy link

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>

@StudentDawid
Copy link
Author

It`s work, Thank you 馃槃

@sujan-sube
Copy link

No problem, glad its working for you. 馃槂

@oskarko
Copy link

oskarko commented Dec 19, 2016

this doesn't work for me :(

@oskarko
Copy link

oskarko commented Dec 19, 2016

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)

@oskarko
Copy link

oskarko commented Dec 19, 2016

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

@StanleyDerLurch
Copy link

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

@0-afflatus
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants