Passing model data to view in Django
<p>I am trying to read info from external database in MySQL.  I created an app inside my project and connected to the external database like this:</p>

<pre><code>'cpu_project': {
  'ENGINE': 'django.db.backends.mysql',   
  'NAME': '***',                         
  'USER': '***',                        
  'PASSWORD': '***',                
  'HOST': '***',                                 
} 
</code></pre>

<p>In my main <code>urls.py</code>, I added this:</p>

<pre><code>  url(r'^cpu/', include('cpu.urls')),
</code></pre>

<p>In the <code>models.py</code> of my app, I have this:</p>

<pre><code>def cpu():
  rows = MyModel.objects.using('mysql').all()
  return render_to_response('cpu/cpu_data.html', {'rows': rows})
</code></pre>

<p>My problem is that I don't know how to pass the data from the model to the view.</p>

<p>I have this in my <code>urls.py</code> from this app:</p>

<pre><code>from . import views

urlpatterns = [
  url(r'^$', views.index, name='index'),
]
</code></pre>

<p>The <code>view.py</code> has this:</p>

<pre><code>from . models import cpu

def index(request):
  return render(request, 'cpu/cpu_data.html')
</code></pre>

<p>And my <code>cpu_data.html</code> has this:</p>

<pre><code>{{ rows }}
</code></pre>

<p>but I see an empty page.  Any ideas about that?</p>

<p>I tried to pass a simple value in the model - I changed this:</p>

<pre><code>rows = MyModel.objects.using('mysql').all()
</code></pre>

<p>to this:</p>

<pre><code>rows = 1
</code></pre>