Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango Template not being rendered correctly using Class based views
    text
    copied!<p>I'm a django newbie and wanted to integrate Singly into the django Polls application. I have used class based views to allow for models from the singly app to be passed along with the Polls models.</p> <p>The problem is, I'm unable to get data from the Singly model even when data is present inside the database.</p> <p>For now I simply want to display the access_token and profile ID of the user profile.</p> <p>Here is my Views.py code: (only the view in question)</p> <pre><code>class IndexView(ListView): context_object_name='latest_poll_list' queryset=Poll.objects.filter(pub_date__lte=timezone.now) \ .order_by('-pub_date')[:5] template_name='polls/index.html' def get_context_data(self, **kwargs): context = super(IndexView, self).get_context_data(**kwargs) context['user_profile'] = UserProfile.objects.all() return context </code></pre> <p>This is my urls.py:</p> <pre><code>urlpatterns = patterns('', url(r'^$', IndexView.as_view(), name='index'), url(r'^(?P&lt;pk&gt;\d+)/$', DetailView.as_view( queryset=Poll.objects.filter(pub_date__lte=timezone.now), model=Poll, template_name='polls/details.html'), name='detail'), url(r'^(?P&lt;pk&gt;\d+)/results/$', DetailView.as_view( queryset=Poll.objects.filter(pub_date__lte=timezone.now), model=Poll, template_name='polls/results.html'), name='results'), url(r'^(?P&lt;poll_id&gt;\d+)/vote/$', 'polls.views.vote', name='vote'), ) </code></pre> <p>And here is my index.html:</p> <pre><code>{% load staticfiles %} &lt;h1&gt;Polls Application&lt;/h1&gt; &lt;h2&gt;Profile Info:&lt;/h2&gt; &lt;div id="access-token-wrapper"&gt; &lt;p&gt;Here's your access token for making API calls directly: &lt;input type="text" id="access-token" value="{{ user_profile.access_token }}" /&gt;&lt;/p&gt; &lt;p&gt;Profiles: &lt;input type="text" id="access-token" value="{{ user_profile.profiles }}" /&gt;&lt;/p&gt; &lt;/div&gt; &lt;link rel="stylesheet" type="text/css" href="{% static 'polls/style.css' %}" /&gt; {% if latest_poll_list %} &lt;ul&gt; {% for poll in latest_poll_list %} &lt;li&gt;&lt;a href="{% url 'polls:detail' poll.id %}"&gt;{{ poll.question }}&lt;/a&gt;&lt;/li&gt; {% endfor %} &lt;/ul&gt; {% else %} &lt;p&gt;No polls are available.&lt;/p&gt; {% endif %} </code></pre> <p>Its able to fetch Polls correctly but it doesn't print anything in either textboxes i.e. the user_profile.access_token and the user_profile.profiles.</p> <p>I think the problem is incorrect rendering of the template. It should pass the context 'user_profile' but its not. Or for some reason its not taking the data from the database, because there is an entry in the UserProfile database.</p> <p>I would be grateful for your help, people.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload