1

so I'm trying to make it possible for a user to share a uniquely generated page. This page pulls variables from the Django database, puts it into python variables, and posts it to the webpage. I want the user to be able to share this page, with the variables. However, it seems that if the variable is generated on that webpage, Facebook can't "see" it. I assume this has something to do with the scope of the variables I use. Here is what I have:

<a id="custom-share" onclick="FB.ui({method: 'feed', link:
'http://www.url.com/', caption: '{{message}}'}, function(response)
{});">Share this on Facebook</a>

Which will pull up a share dialogue with the caption {{message}}. What I've tried:

  1. I tried using {% load set_var %} with {% set message = e.text %} where e.text is the variable being pulled from the database. For some reason when I try to share {{message}}, it pops up blanks. When I try to insert {{message}} elsewhere on the page, it works though.

  2. I then tried to see if a variable, passed through views.py would work. This works, but is not the variable I want to be passed to the FB share.

So here I am, I tried to different python variables, and one works and one doesn't. Any ideas on how I can get to change the description dynamically?

Milap
  • 147
  • 1
  • 6
  • 15
  • In general, variables passed in from the view should be scoped to the entire template, but not included templates. I assume you are getting set_var from this: http://www.soyoucode.com/2011/set-variable-django-template. But I don't understand why you need {% set message = e.text %} if you already have e.text in the template. What does caption: '{{ e.text }}' do? If you check the source of the page, is the variable being interpolated where you expect? Maybe this is a problem with the FB app. Might need to see more of your template, and the generated HTML, to debug this. – Brett Mar 27 '14 at 00:27
  • because there are several e.text's. Here's what I did: {% for e in entries1 %} {{ e.text }} {% endfor %} several times where entries1 is in views.py and reaches for a variable in my database randomly. Is there a way for me to reach for this variable in views.py and THEN pass to the template? – Milap Mar 27 '14 at 02:21
  • Your view can certainly pick one entry at random and pass that into the template (see: http://stackoverflow.com/questions/306400/how-do-i-randomly-select-an-item-from-a-list-using-python) instead of the entire list of entries. In normal usage you don't pass variables from the template back into the view. Sorry if I'm not getting the problem. Might need to see more model, view and template code to really understand what you're trying to do. – Brett Mar 27 '14 at 02:46

0 Answers0