mailgun for loop doesn't render email correctly - mailgun

I have copied for loop example from mailgun documentation page and trying to make it work, but it doesn't recognize as a code
{% for item in items %}
<span>{{ item }} </span>
{% endfor %}
the above code renders as
{% for item in items %} test_item {% endfor %}
in the email when it is sent or reviewed in the email review.
Do I need to enable something? {{name}} by itself works ok, loop doesn't work

Related

Github Pages: adding an if condition in index.html

I have a blog created on Github Pages using Jekyll Now
The default Index.html looks like this
---
layout: default
---
<div class="posts">
{% for post in site.posts %}
<article class="post">
<h2>{{ post.title }}</h2>
<div class="entry">
{{ post.excerpt }}
</div>
Read More
</article>
{% endfor %}
</div>
This creates a landing page where the titles of all the posts you have made in the _posts directory are displayed with a link.
Looking at the {% for ... %} & {% endfor %} & the final static HTML, it seems as if when building the page, the for tag is actually iterated & the final HTML contains a list of actual titles.
I want to change this so that not all posts are listed. I do not want to list any post whose title contains the string "BEINGWRITTEN"
I tried stuff like
{% for post in site.posts %}
{% if (post.title.indexOf('BEINGWRITTEN') == -1) %}
<article class="post">
...
</article>
{% endif %}
{% endfor %}
Also tried with includes instead of indexOf, that also doesn't work. Both cases, I don't see any posts linked at all on the landing page.
How do I do this?
I did this by adding a category in the front matter of the page I don't want included.
i.e.
category: noshow
Then changed the index.html to
{% for post in site.posts %}
{% unless post.category == "noshow" %}
.....
{%endunless}
{%endfor}

Django load more comments with AJAX [duplicate]

This question already has an answer here:
How to load more content in django application?
(1 answer)
Closed 3 years ago.
In the profile page, I want to display posts of a user. Each post might have several comments, I don't want to display all the comments to the post instead I want to display only few comments and add load more comments option. If a user clicks load more comments then I want to display some more comments. What is better way to do this? I am already using infinite scroll using pagination for posts. I think this may not work for comments.
My currents code looks like below
{% for post in post_queryset %}
<div class="title">
{{ post.title }}
</div>
{% for comment in post.comments.all %}
</div>
{{ comment.text }}
</div>
{% endfor %}
{% endfor %}
Above code simplified version of original to make things easier.
For dynamic page content, the best way to go is to use jquery and bootstrap.
When rendering the template, you could add the class "d-none" (which hides the content of the element) in the 10th or latter element:
{% for post in post_queryset %}
<div name="comment-block">
<div class="title">
{{ post.title }}
</div>
{% for comment in post.comments.all %}
<div {% if forloop.counter > 9 %} class="d-none" {% endif %} >
{{ comment.text }}
</div>
{% endfor %}
<button type="button" name="more_comments" class="btn btn-primary" > more comments </button>
</div>
{% endfor %}
This way, all the comments will be rendered, but only the first 10 will be on display.
After that, a jquery function triggered by the button click should do the trick
$("[name='more_comments']".click(function(){
var hidden_comments = $(this).parent().find('.d-none'); // selects all hidden comments
$(hidden_comments).each(function(){$(this).removeClass('d-none')}); // removes 'd-none' class
})
Keep in mind that your original code, neither my answer, does not comply with bootstrap, which is highly recommended. You can learn more about bootstrap in https://getbootstrap.com/.

Django - Nothing happens when "submit" button is clicked in a ModelForm?

Ok, so I am making a project, where you can make new blogposts and edit existing blogposts in Python with Django, but when I want to make a new post on my website, the "submit" button in new_post.html does nothing when I press it. I fill in the 'title' field and I fill in the 'text' field from the ModelForm "BlogPostForm" and press the button. In the terminal there's no POST or GET request. I just don't know why?
I'm using Python 3.6.4 and Django 2.1, installed in a virtual environment created by the "venv" module.
base.html:
<p>
Blogs
</p>
{% block content %}{% endblock content %}
index.html:
{% extends "blogs/base.html" %}
{% block content %}
<p>All posts:</p>
<ul>
{% for blog in blogs %}
<li>
{{ blog }}
<p>{{ blog.date_added|date:'M D, Y H:i' }}</p>
<p>{{ blog.text|linebreaks }}</p>
<p>-------------------------------------<p>
</li>
{% empty %}
<li>No posts are posted yet.</li>
<p>
Add new post
</p>
{% endfor %}
</ul>
<p>
Add new post
</p>
{% endblock content %}
new_post.html:
{% extends "blogs/base.html" %}
{% block content %}
<p>Make a new post:</p>
<post action="{% url 'blogs:new_post' %}" method='post'>
{% csrf_token %}
{{ post.as_p }}
<button name='submit'>Add Post</button>
</post>
{% endblock content %}
Thanks in advance!
There is no <post> tag in HTML. To post a data you need to use a <form> tag. Everything else is correct.

Django Messages, How to Hide Specific Ones

I am using Django's messages framework to indicate successful actions and failed actions.
How can I exclude account sign in and sign out messages? Currently, landing on a page after signing in displays
Successfully signed in as 'username'. I do not want this message to be displayed, but all other success messages should be displayed. What I attempted is shown below. I tried using logic to find if the message had the word "signed" in it. If it did, do not display it. That however is not working though.
{% if messages %}
<div class="db-section">
<ul class="messages">
{% for message in messages %}
{% if "signed" in message %}
# Don't display anything
{% else %}
<div class="alert alert-error">
<strong style="color:{% if 'success' in message.tags %}green{% else %} red {% endif %};padding-bottom:10px;">{{ message }}</strong>
</div>
{% endif %}
{% endfor %}
</ul>
</div>
{% endif %}
Could someone possibly explain why the above code is still displaying messages that even contain "signed" in it?
Use safe filter to convert that message object attribute to actual string and compare
--- Your code ---
{% if "signed" in message|safe %}
# Don't display anything
{% else %}
--- Your remaining code ---

Django displaying selected items from multiple select in template

I have a multiple select in a ModelForm. When the page reloads with an error I want the currently selected items to be displayed.
view.html
error: {{ form.recipients.errors }}<br/>
currently selected: <br/>
{% for recipient in form.recipients %} <!--I want some type of loop through only the selected items in my recipients -->
{{ recipient }}<br/>
{% endfor %}
{{ form.recipients }}
You want to loop the value of the field, not the field itself:
{% for recipient in form.recipients.value %}
{{ recipient }}
{% endfor %}