Add Facebook share button to Django application - django

I am using Facebook's share button on my Django app.
I'm using Facebook's SKD instructions which tell me to place this code wherever you want the plugin to appear on your page:
<div class="fb-share-button"
data-href="https://my-website-full-url"
data-layout="button" data-size="small" data-mobile-iframe="false">
<a class="fb-xfbml-parse-ignore" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fplugins%2F&src=sdkpreparse">Share
</a>
</div>
So I placed that code in my template but how do I add the full URL of the web page with the FB share button in the data-href attribute?

As long as you have django.template.context_processors.request enabled you should be able to use request.build_absolute_uri() in your template:
data-href="{{ request.build_absolute_uri }}"
This should work out of the box if you're using a fairly recent version of Django.

Related

Using customGPlusSignIn with data-onsuccess method instead of onclick

I am trying to change the file path of my website after having the user sign in.
Here is my body html code
<body>
<div id="map"></div>
<div id="loginmain">
<div id="center">
<div id="login-center">
<img src="Assets/google.svg">
<a id="customBtn" class="customGPlusSignIn" onclick="document.location='index.html'">Sign In</a>
<script>startApp();</script>
</div>
<p id="help-text">Sign in with your school Google account</p>
</div>
</body>
The intention of the onclick method is to call a separate html page, after the user has successfully signed in to Google. However, using onclick would change the file path regardless of the Google Sign in.
I have tried using data-onsuccess method, however it seems to be a method only for class = "g-signin2".
Instead, I am using class="customGPlusSignIn", and I'm not particularly sure how to change the file path after ensuring that the user has successfully signed in.
For context, the function startApp() is copied over from Google's sign in docs, from the bottommost code cell.
Could anyone help me with this? Thanks

Load django template dynamically

I've 2 section in my screen. Left section is for showing tabs and right is for displaying that tab template(as shown in screenshot). I'm not able to understand how to load different templates when I click these tabs
For example, when I click change password, I should be able to load change_password.html template
This is by far I've tried with code.
<div class="nav">
<ul>
<li class="active"></i><span class="hidden-xs hidden-sm">Home</span></li>
<li></i><span class="hidden-xs hidden-sm">Change Password</span></li>
<li>Bookings</span></li>
<li></i><span class="hidden-xs hidden-sm">Settings</span></li>
</ul>
</div>
I've tried to use with but no luck.
I've just started with django, so if anything is missed let me know. Thanks for your help!
Screenshot
I think what you're attempting is not possible. If you don't want a page reload upon clicking on a tab, you need to use Javascript to dynamically show/hide elements. If page reload is acceptable, you can create different views for each tab, each view rendering a different html file.
You can use the Django include tag to render another template with the current context. E.g. {% include "foo/bar.html" %} (see documentation here). But this will not solve your problem of displaying different content upon clicking on a tab.

Link to a specific div in another app(page) in Django using anchor tag

I have a div with a certain id
<div id="services">
Then I try to link to it using Django templates
<a href="{% url 'homepage' %}#services">
But it only works if I'm in the same page (App)
Is there a way to work around this ?
I found out what the problem was. I had a script that does smooth scrolling and it had "event.preventDefault();" in it. as I removed that it worked.

Facebook Profile Picture not showing in Chrome

I am having issue with loading Facebook Profile Images in my application. I get list of my friends fromt the graph API and then display the relevant Friend Info and their public profile images
My HTML is as below.
<div id = "profile_picture" style="float:left; width:100px;height: 100px" >
<img src="https://graph.facebook.com/{{providerUserId}}/picture?width=100&height=100"/>
</div>
<div id="user_basic_info" style="float:left;margin-left:14px;">
<div id="name" style="font-size:16px;font-weight:bold;margin-bottom:6px;">{{name}}</div>
<div id="email" style="margin-bottom:6px;width:400px;">{{email}}</div>
<div id="address"></div>
</div>
The {{}} are Mustache templates which get populated via the model.
For some reason the images don't load up in Chrome; but work fine in Chrome Canary, Firefox, Safari.
It doesn't make a difference if I pass in hardcoded userId also.
Any guidance??
Check to see if you have any chrome plugins causing the issue by opening the url in incognito mode, that is assuming you have all the extensions disabled in that mode.
I noticed that the disconnect extension hid the images as you described.

Create a PDF or Printable version of change_list.html in Django Admin

I would like to add a tool link at the top of my admin change_list.html, which I have already done, and have this link basically be able to produce some sort of printable document version of my models data based off of my current filter settings. Basically a print button in the admin change_list.html.
so far I have overridden the change_list.html to create the link, and I notice that this
<li>
<a href="{{ choice.query_string|iriencode }}" class="addlink">
{% blocktrans %}View PDF{% endblocktrans %}
</a>
</li>
gives you a link based on these choices.. but Im kinda lost as to the best/easiest way to do this..
Sorry, new to Django. I know I can use ReportLabs to generate pdfs, but not a 100% on how to get the filtered data from change_list to it.
A bit late, but for those who might be searching "in the future" like me, this might be helpful: http://djangosnippets.org/snippets/1842/