Django like button not showing - django

after following the instructions here I have set up django-facebook-like app but the problem is that I cannot see any like button on my page. is there a particular tag I must use in order to display the button or does the button automatically display at the bottom of every page after setting up. I am confused about the last part though. I dont really understand this addition. Can anyone help me. What am I missing
base.html
</head>
{% load like_button %}
<body>
{% like_button_js_tag %}
</body>
</html>

Related

How to avoid that Django adds url link to every html element that follows the link

i would like to achieve something very basic in Django but can't find out what I am doing wrong. On my apps "index.html", I would like to add a button which redirects to another html template ("site.html") with other content. I added the following to "index.html" which is working:
<body>
<h2>foo</h2>
{% block content %}
<button><a href="{% url 'site' %}"/>Click</button>
{% endblock %}
<p>bar</p>
</body>
Clicking on the button gets me to "site.html", however all html items which I add on "index.html", for example the paragraph "bar" would also get rendered as hyperlink.
I tried creating different Django blocks or making different html sections but that doesn't fix it.
Thank you for your help.
You're missing a closing anchor </a> tag after your element.
<body>
<h2>foo</h2>
{% block content %}
<button>Click</button>
{% endblock %}
<p>bar</p>
</body>
I will note that I'm not sure it's "correct" to have an anchor tag within a button. I think you're better off styling your anchor tag to appear as a button.

Overriding <head> tag within Django template

I have a Django application where users upload videos (played back via html5 video tag). To handle edge cases where a user is unable to playback the video, I give them the option to download it.
For this, I'm writing JS that ensures a "download" button appears whenever a src isn't loading. Here take a look: http://plnkr.co/edit/o8YFZNaEhpJMg4YPhZCO?p=preview
The problem is that my JS resides within <head></head> and it needs to be able to access all videos I'm going to show on page.
Normally, I pass video objects as an object_list that I then iterate through (generated through a paginated ListView). But all this happens in the body of template.
How can I get access to context[object_list] within <head> so that the JS snippet I've shared can utilize the sources (I'm already inheriting <head> from base.html)? Secondly, how do I ensure I only pass video sources in page to my JS snippet?
Can someone give me an illustrative example via which I can solve this?
Define a block in your base.html that you can override in your object list template.
See https://docs.djangoproject.com/en/1.11/ref/templates/language/#template-inheritance
You can do it by adding a
{% block video_head_tag %}
{% endblock %}
inside your <head></head> tag in the parent template "base.html"
on your child template
{% extends "base.html" %}
{% block video_head_tag %}you_object_list{% endblock %}
Reference https://docs.djangoproject.com/en/4.1/ref/templates/language/#template-inheritance

Using same angular js controller twice with django template on same page

I tried to find the solution to this problem on stackoverflow and google but couldn't find it. The issue is using same controller twice on the same page and only the first controller mention gets invoked.
So I have a base template and main page. Now mainpage inherits two completely different blocks - sidebar block and main content block. both needs my controller - myController but the moment I use ngController with same controller name on the page twice on these two completely different divs only the first one gets executed.
Gist: https://gist.github.com/keshavagrawal89/356bb68068ac3ed4ae4e#file-samecontroller
<!-- base.html -->
<div>{% block sidebar %}{% endblock %}</div>
<div>{% block content %}{% endblock %}</div>
<!-- MainPage.html -->
{% block sidebar %}
<ul ng-app="myApp" ng-controller="myController">
<li></li>
</ul>
{% endblock %}
{% block content %}
<div ng-app="myApp" ng-controller="myController"> my page content</div>
{% endblock %}
What am I missing?
You cannot use multiple ng-apps in the same application. Ideally you would just put it in the root of your app or create an app including multiple apps and place it in the root, in the example below all the entities registered in both the apps will be loaded into the myApp module.
ex:-
angular.module('myApp', ['App1', 'App2']);
But in your case it seems like your app may or may not be the same, so best way would be to manually bootstrap your app.
But remember when manually bootstrap your app it is generally not to use ng-app
angular.element().ready(function() {
angular.bootstrap(elmRoot, ['myApp']);
});
Plnkr
Note: You should not use the ng-app directive when manually bootstrapping your app.
the only problem with your code is multiple ng-app's as PSL says on the comment.
ng-app declares the scope for DOM objects for angularjs to parse and it should be use once
typically in the html tag like
<html ng-app="app"> or <html ng-app>
i recommed using a name for the app module
here is a working example

How to join(nest) django apps in site

Last time i make my way through python library - django. I have idea how MVC model works and other basics about creating django projects. I'm going to create site in django but there is one thing that loom large in my mind.
After i will create apps for managing articles, polls, and other likely to change content of site, i have to join it together on one page. By lack of knowledge it looks awful for me.
To make index page, i mind to create app and connect it in URLconf to '^$'. Then, i will have large template containing everything in html - head, meta, includes(js, css) etc. It doesn't sounds good for me(probably lack of knowledge). Look..
How i will be able to get link to specific content on site(i.e. article) to give it to somebody? I need /article/2013/02/55 show specific article but it needs to use my index page for meta, includes, entire structure of site etc. I can't imagine how I will be able to connect it together.
I'm in the course of "The Definitive Guide to Django: Web Development Done Right" book. Maybe i will get answer later but I'm nervous and impatient. It would be great to make use of ajax and some jquery-ui on site but i can't even imagine how to do static site with nested apps!
You just need to extend the base template and use blocks.
base.html
<html>
<head>
<title>...</title>
<link rel="stylesheet" type="text/css" href="...">
<script>...</script>
</head>
<body>
{% block content %}
Content from the base template
{% endblock content %}
</body>
</html>
appname/templatename.html
{% extends "base.html" %}
{% block content %}
Content from the app template to replace other content
{% endblock content %}
See the docs for more info on template inheritance.

Django Override blocks in template from within iframe

I have a template structured as follows:
<html>
<head><title> {%block title %} Default title {% endblock %} </title> </head>
<body>
<iframe>
<head> <title> {% block title %} Title for frame {% endblock %} </title> </head>
<body> Main content. This is what people see on the web page. </body>
</iframe>
<!-- Content that I do not want to reload every time. A player, to be precise. -->
</body>
</html>
Within the iframe, I inherit templates and so on, to display my final page. The title block within the iframe gets replaced properly, and the title of the iframe is what it should be.
However, I want to replace the title of the parent frame, when I load a page inside the iframe. Is it possible to do this? I don't want to do it via Javascript, because that defeats the purpose of SEO. I want the title to be changed when the page is loaded itself, from the server side.
Thanks in advance.
You have two blocks named with name title. Rename one of them and everything should work fine. The Django template construction isn't influenced at all if you are working with iframe or with any other element.
EDIT:
When an iframe gets a new location it sends a request to the server and renders all of its response inside the iframe. So no it is not possible to leverage Django's template system for a change in the iframe's parent site.
I am no SEO expert but using an iframe like this will probably not be liked by a search engine anyway. You should implement the traditional click-pageload way. If you want to speed things up you can use JavaScript on top of that. Captchure your menu clicks and load the needed parts of the site asynchronously. This way both you and your search engine can be happy :)