Refreshing a specific div every few seconds in django using javascript
<p>I am trying to refresh the content of a table every few seconds in my html page using javascript. I keep getting 500 error when it tries to refresh the div, internal server error. Could someone enlighten the reason this is not working? I have used this: <a href="http://stackoverflow.com/questions/3776571/refresh-div-using-jquery-in-django-while-using-the-template-system">Refresh div using JQuery in Django while using the template system</a>
 as reference to what I was doing. The page loads perfectly the first time just fails to refresh.</p>

<p>Here is my code:</p>

<p>urls.py</p>

<pre><code>url(r'^specialScoreboard/$', views.specialScoreboard.as_view(), name='specialScoreboard'),
url(r'^specialScoreboardDiv/$', views.specialScoreboardDiv , name='specialScoreboardDiv'),
</code></pre>

<p>views.py</p>

<pre><code>class specialScoreboard(generic.ListView):
    template_name = 'CTF/specialScoreboard.html'
    context_object_name = 'teams'

    @method_decorator(login_required)
    @method_decorator(never_ever_cache)
    def dispatch(self, request, *args, **kwargs):
        if getAnyActiveGame and request.user.is_staff:
            return super(specialScoreboard, self).dispatch(request, *args, **kwargs)
        else:
            return HttpResponseRedirect(reverse('CTF:no_active_game'))

    def get_queryset(self):
         """
            ordering teams by score
        """
        game = getAnyActiveGame()
        teams = get_teams_from_game(game)
        return sorted(teams, key=lambda a: a.get_score(game), reverse=True)

def specialScoreboardDiv():
    game = getAnyActiveGame()
    teams = get_teams_from_game(game)
    sortedList = sorted(teams, key=lambda a: a.get_score(game), reverse=True)
    return render_to_response('CTF/specialscoreboardDiv.html' , {'sortedList' :sortedList})
</code></pre>

<p>scoreboardRefresh.js + scoreboardDiv.html</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>&lt; script &gt;
  var scoreboardURL = '{% url '
CTF: specialScoreboardDiv ' %}';

function refresh() {
  $.ajax({
    url: scoreboardURL,
    success: function(data) {
      $('#scoreboardDiv').html(data);
    }
  });
};
$(document).ready(function($) {
  refresh();
  setInterval("refresh()", 3000);
})

&lt; /script&gt;</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="panel panel-info"&gt;
  &lt;div class="panel-heading"&gt;Scoreboard&lt;/div&gt;
  &lt;div class="panel-body"&gt;

    &lt;div class="table-striped"&gt;
      &lt;table id="scoreboardDiv" class="table table-hover"&gt;
        &lt;thead&gt;
          &lt;tr&gt;
            &lt;th&gt;#&lt;/th&gt;
            &lt;th&gt;Team Name&lt;/th&gt;
            &lt;th&gt;Score&lt;/th&gt;
          &lt;/tr&gt;
        &lt;/thead&gt;
        &lt;tbody&gt;
          {% for team in teams %}
          &lt;tr&gt;
            &lt;td&gt;{{forloop.counter}}&lt;/td&gt;
            &lt;td&gt;{{team.name}}&lt;/td&gt;
            &lt;td&gt;{{team|getScoreTeam}}&lt;/td&gt;
          &lt;/tr&gt;
          {% endfor %}
        &lt;/tbody&gt;
      &lt;/table&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;</code></pre>
</div>
</div>
</p>

<p>i can't seem to be able to format the error, here is a picture of it: <a href="http://i.imgur.com/Yc11juA.png" rel="nofollow">http://i.imgur.com/Yc11juA.png</a>
<a href="http://i.imgur.com/QluqZyc.png" rel="nofollow">http://i.imgur.com/QluqZyc.png</a>
<a href="http://imgur.com/QluqZyc" rel="nofollow">http://imgur.com/QluqZyc</a></p>

<p>Your django view takes no arguments, but usually django tries to pass request param into it. From the error in the screenshot you provided in comments, looks likÐµ this is your problem. </p>

<p>I think you error will be fixed by making your view function take this argument:</p>

<pre><code>def specialScoreboardDiv(request):
    game = getAnyActiveGame()
    ...
</code></pre>

javascript jquery python html django