Django messages not displaying on webpage - django-forms

I created and imported the usual "django.contrib" from message, attached is the code snippet for my view.py page and register.html.When I tried to register a new user, I"m not getting the warning message on the webpage instead all I get is "<django.contrib.messages.storage.fallback.FallbackStorage object at 0x00000230B847FEE0>" i don't know what am doing wrong. Please help Thanks in advance.enter image description here

messages in django is a class , for display messages you need to iterate on it
{% if messages %}
<ul class="messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
django docs

Related

NUNJUCKS setting a variable

Hi all Im calling data from a json file. Whe I create the following loop:
{% for item in resume.applications %}
<span class="expanded uppercase">{{ item.fields.Job }}</span>
{{ item.fields.intro | safe }}
{% endfor %}
The span renders with the correct html content. However if I try to set a variable without a loop:
{% set job = resume.applications %}
<span>{{ job.fields.intro }}</span>
I get nothing? Not sure what I'm doing wrong. Thanks.
I get nothing

Jekyll Pagination Path Doesn't Include Page Number

I am attempting to create pagination in Jekyll under the path '/notes/'.
In my _config.yml, I have:
paginate: 2
paginate_path: "/notes/:num/"
In my /notes/index.html, I have:
<div class="pagination">
{% if paginator.previous_page %}
Previous
{% else %}
<span class="previous section link">Previous</span>
{% endif %}
<span class="page_number section">{{ paginator.page }} / {{ paginator.total_pages }}</span>
{% if paginator.next_page %}
Next
{% else %}
<span class="next section link">Next</span>
{% endif %}
</div>
When I load http://localhost:4000/notes, I see that the 'Previous' link is not linking to /notes/2, but instead it simply links to /notes/, the page that I am already on. Additionally, when looking in the generated _site folder, I see that /notes/2 has not been created, despite having more than two posts created.
So, I suppose my question is, how can I fix this and get jekyll to paginate properly?

How to use Jekyll's pagination tool to sort through a subdirectory within _posts

Having trouble getting pagination to work properly in Jekyll using liquid markdown.
Used the paginator function and the posts do paginate but I'm trying to figure out a way to filter out what paginates.
Within my _posts directory I have a blog sub directory and a news subdirectory. I'm trying to only paginate the articles in blog and not news.
{% assign posts = site.posts | where: 'category','Blog' %}
<ul class="list-unstyled blog-list">
<!-- This loops through the paginated posts -->
{% for post in paginator.posts %}
{% assign posts = site.posts | where: 'category','Blog' %}
{% if post.category == 'Blog' %}
Do Stuff
{% endif %}
{% endfor %}
<!-- Pagination links -->
<div class="pagination">
{% if paginator.previous_page == 1 %}
Previous
{% endif %}
{% if paginator.previous_page > 1%}
Previous
{% endif %}
<span class="page_number ">Page: {{ paginator.page }} of {{ paginator.total_pages }}</span>
{% if paginator.next_page %}
Next
{% endif %}
</div>
</ul>
I was trying to retrieve posts that have the category 'Blog' but when I run it, it paginates to the 7 articles per page I wanted, but some pages have less then 7 articles or no articles show up at all.
I think somethings wrong with my loop logic but I'm not sure what.
Maybe it's grabbing all the articles in _posts regardless but not showing the news articles on the page?
Thanks!
Jekyll Paginate does not have filtering features therefore it's not possible to filter paginated posts by category. I'd recommend You to look into Octopress Paginate plug-in which provides the feature.

Create categories in Jekyll _data?

I need help using _data in Jekyll to generate content.
Let's say I want to create a directory displaying countries that have blocked Twitter and Facebook. I understand how to query the _data folder but how do I create something like categories in the _data .yml and query that data?
Let me try to explain.
Twitter is blocked in Turkey & Iran so I'd start with this (networks.yml in _data):
- network: Twitter
This is where I get stuck. What I don't understand is if I'd want to "tag" or "categorize" Twitter like this:
- network: Twitter
blockedcountries: [Turkey, Iran, Iraq]
- network: Facebook
blockedcountries: [Iraq, Turkey]
Then I'd want pages at mysite.com/turkey/ that would display the networks tagged with turkey. Something like this:
{% for network in site.data.networks %}
{% if network.blockedcountries == Turkey %}
<li>{{ network.network }} is blocked in Turkey</li>
{% endif %}
{% endfor %}`
Which would display:
- Twitter is blocked in Turkey
- Facebook is blocked in Turkey
Appreciate any help and will tip Bitcoin if solved!
Your YAML is right. The Problem seems to be in your if statement:
{% if network.blockedcountries == Turkey %}
network.blockedcountries is an array(a list) and therefore your if statement needs to be like this:
{% if network.blockedcountries contains "Turkey" %}
<li>{{ network.network }} is blocked in Turkey</li>
{% endif %}
Jekyll is using the Liquid markup language for its templates. You can read more about its possibilities here. Maybe the liquid case statement is also helpful for further optimization.
Here is my "full" solution:
My data in _data/networks.yml
- name: Twitter
blockedcountries: [Turkey, Iraq, Iran]
- name: Facebook
blockedcountries: [Turkey, Iraq]
My liquid template in index.html
<ul>
{% for network in site.data.networks %}
{% if network.blockedcountries contains "Turkey" %}
<li>{{ network.name }} is blocked in Turkey!</li>
{% endif %}
{% endfor %}
</ul>

How do I add a link to an external site the main navbar in CKAN

I know that I can customize the set of navigation links at the top of the page in the standard template by overriding the header_site_navigation_tabs block e.g. as in the [datahub.io customization](https://github.com/okfn/ckanext-datahub/blob/3d64748fc1f3c4499780b199e971a5929ba69315/ckanext/datahub/templates/header.html#L9
)
{% block header_site_navigation_tabs %}
{{ h.build_nav_main(
('search', _('Datasets')),
('organizations_index', _('Organizations')),
('about', _('About'))
) }}
{% endblock %}
However, I want to add a link to this list to an external website? Can I just do (see extra entry at the end):
{% block header_site_navigation_tabs %}
{{ h.build_nav_main(
('search', _('Datasets')),
('organizations_index', _('Organizations')),
('about', _('About'))
('http://blog.datahub.io/', 'Blog')
) }}
{% endblock %}
No, you can't do that. The helper method looks for routes declared internally (config['routes.named_routes']). You can, however, simply add a li element, so the whole block would look like this
{% block header_site_navigation %}
<nav class="section navigation">
<ul class="nav nav-pills">
{% block header_site_navigation_tabs %}
{{ h.build_nav_main(
('search', _('Datasets')),
('organizations_index', _('Organizations')),
('about', _('About'))
) }}
<li>Blog</li>
{% endblock %}
</ul>
</nav>
{% endblock %}

Resources