Blog is showing code and not page - python-2.7

hii I am novice to python and django. I am referring one tutorial to develop a blog in django.
I have synchronized the database and have run the server.
My admin page is working fine but my application page is showing some problem
I have created an html file "blog.html"
(% extends "base.html" %)
(% block content %)
(% for post in object_list %)
<h3>{{ post.title}}</h3>
<div class="post_meta">
on {{post.date}}
</div>
<div class= "post_body">
{{post.body|safe|linebreaks}}
</div>
(%endfor %)
(%endblock %)
When i run my django, it is showing this code inspite of actual blog page..

Django's template language uses {% and %} for template tags, not (% and %) as in your template file.

Related

External URL into a iframe to embed an external url within Django

I would like to embed a pptx that is uploaded into a folder in OneDrive within a iframe tag in a Django template. I have the urls stored in a model and saved into the SQLite database. In this sense, in the views.py file, I have the following code:
context = {
'selectedunit': selectedunit,
'url_to_be_inserted': MyModel.objects.filter(unit=selectedunit)
}
return render(request, 'web.html', context)
The code for web.html is very easy:
{% extends 'base.html' %}
{% load static %}
{% block content %}
<div class="container col-lg-8">
<div class="center">
<iframe class="center" src={{ url_to_be_inserted.url }} width="100%" height="300%" frameborder="0"/>
</div>
</div>
{% endblock %}
The result is the snapshot below:
While, I would like to embed the ppt into the web site. If I directly insert the URL, instead of using the context variable, it works. That is to say:
<iframe class="center" src="https://..." width="100%" height="300%" frameborder="0"/>
In this case, the result is as follows (ppt embedded into the Web site):
The reason why doing in this sense is because, depending on the selectedunit variable, I would like to address a different pptx with a different URL and I would like to dynamically change the pointer (as you see above by filtering the model).
How could I solve it?
Many thanks in advance

django cms - how to make placeholders inheritable from base.html

I made in my base.html (which will be inherited from all other templates) this:
<a href="/./">
{% placeholder "Logo-Image" or %}
There is no Logo image yet.
{% endplaceholder %}
</a>
I was in Startpage and uploaded a Logo image, worked well. but once I navigated to another pages, the uploaded logo isnot there, instead i see: There is no Logo image yet.
How can I make this placeholder also inheritable?
I tried in another page this:
{% show_placeholder "Logo-Image" inherit %}
but not a single sign of success
I solved the issue. Django CMS has since version 3.0 a new tag called:
static_placeholder
to make it work:
just do in your base.html
{% static_placeholder "logo" or %}
There is no Logo image yet.
{% endstatic_placeholder %}``
and all other pages inherit this.

Redirected Octopress blog on Github pages shows only Archives link instead of the latest posts

I have set up Octopress with my Github account at http://acgrama.github.io/. The main page is a vanilla HTML, non-Octopress landing page, and the blog is set up in Octopress under source/blog.
(I have followed the instructions in the "Landing Page vs. Blog Index" section of http://octopress.org/docs/theme/template/)
Everything is ok, except when I go to http://acgrama.github.io/blog/ I see a link to the blog archives instead of the latest blog posts.
Some symptoms that I noticed: when I do rake generate, I get the following output:
## Generating Site with Jekyll
identical source/stylesheets/screen.css
Configuration file: /home/***/octopress/_config.yml
Source: source
Destination: public
Generating...
Pagination: Pagination is enabled, but I couldn't find an index.html page to use as the pagination template. Skipping pagination.
done.
Looking under source/blog/index.html, I understand that the posts in paginator.posts are iterated and shown (?), after which the Older/Newer and Blog Archives links are shown:
<div class="blog-index">
{% assign index = true %}
{% for post in paginator.posts %}
{% assign content = post.content %}
<article>
{% include article.html %}
</article>
{% endfor %}
<div class="pagination">
{% if paginator.next_page %}
<a class="prev" href="{{paginator.next_page_path}}">← Older</a>
{% endif %}
Blog Archives
{% if paginator.previous_page %}
<a class="next" href="{{paginator.previous_page_path}}">Newer →</a>
{% endif %}
</div>
</div>
These made me think that paginator.posts is empty for some reason, hence nothing happens in the first for loop and this is how only the Blog Archive link ends up being shown.
Am I doing anything wrong? Can this issue be solved at all?
I had the exact same issue and I found an answer based on your suspicion that paginator.posts was empty.
Update _config.yml and set the following:
paginate_path: "posts/:num"
to
paginate_path: "blog/posts/:num"
After that and a rake generate and rake preview, the /blog page showed my posts
This would lead me to believe that the paginator must be made aware of the subdirectory change for /blog. Really seems like something that should be in the docs

Edit Django admin logout template?

I want to make a very small change to the Django admin logout page.
I know how to use templates to override the Django admin templates, so I have tried to do the same thing with the logout file.
I have set up a new template at templates/registration/logged_out.html. The content of this file is as follows:
{% extends "registration/logged_out.html" %}
{% block content %}
<p>Thanks for using the site.</p>
<p>Log in again</p>
<p>Return to the home page</p>
{% endblock %}
However, something is definitely wrong, because when I try to log out of admin, the site stops running.
I've found the Django docs page recommending the use of AdminSite for changes to the base template and logout pages, but is this really necessary for such a tiny change?
If so, does anyone have an example of how I might set up the logout template? I'm rather intimidated by the instructions for AdminSite.
Thanks.
The reason of manage.py runserver termination is an inheritance loop.
Django loads "registration/logged_out.html" and that it tries to load it's parent: "registration/logged_out.html". Unfortunately parent is the same template and so we end up on the template inheritance loop.
Manage.py will terminate with some variant of stack overflow error...
You can easily escape the issue by extending the parent of original "registration/logged_out.html" -> "admin/base_site.html". I.e:
{% extends "admin/base_site.html" %}
{% load i18n %}
{% block breadcrumbs %}<div class="breadcrumbs">{% trans 'Home' %}</div>{% endblock %}
{% block content %}
<p>Thanks for using the site.</p>
<p>Log in again</p>
<p>Return to the home page</p>
{% endblock %}
You're getting a template import loop. The template loader won't load the base template form wherever you've got Django installed, because it sees that you have that template in your project's template folder.
I think you'll need to copy the log out template from where you have Django installed to your project's template folder. Unfortunately that's the only way that seems to work. This method also means that if updates are made to the Django admin templates, you'll have to manually apply them to your modified templates.

Problem embedding youtube video's with with django template

I have a django template that displays a list of objects with youtube videos:
{% for obj in objs %}
<h1>{{ obj.name }}</h1>
<iframe width="425" height="349" src="{{ obj.video}}" frameborder="0" allowfullscreen=""></iframe>
{% endfor %}
obj.video is stord as a urlField. When I load the page chrome console gives me the error refused to display document because display forbidden by x-frame-options.
The problem persists if I replace {{ obj.video }} with a manually written youtube embed url such as http://youtu.be/zzfQwXEqYaI. However, if I replace it with something like www.google.com the iframes will load.
Try embedding the video like with url like:
http://www.youtube.com/embed/zzfQwXEqYaI
I guess its some kind of protection from youtube