title: Is there a simple way to display mysql data in Django template without creating an app?
body: <p>I have a table in my MySQL database named mysite_categories, there are 4 columns but for my purposes I just need two (name, base_url).</p>
  
  <p>I currently have a template '*base_categories.html*' that I use to load the categories manually.</p>
  
  <p><strong>base_categories.html (trimmed down)</strong></p>
  
  <pre><code>{% block content %}
    &lt;div class="section" style="float: right;"&gt;
      &lt;h4 class="gradient"&gt;Category List&lt;/h4&gt;
      &lt;ul&gt;
        &lt;li&gt;&lt;a href="/categories/Art" id="nav_font"&gt;Art&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="/categories/Biography" id="nav_font"&gt;Biography&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="/categories/Science" id="nav_font"&gt;Science&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/div&gt;
  {% endblock %}
  </code></pre>
  
  <p>What I'd like to do is pull the data from the db and use it in a for loop. Something like:</p>
  
  <pre><code>{% block content %}
    &lt;div class="section" style="float: right;"&gt;
      &lt;h4 class="gradient"&gt;Category List&lt;/h4&gt;
      &lt;ul&gt;
        {% for category in mysite_categories %}
          &lt;li&gt;&lt;a href="{{ category.base_url }}" id="nav_font"&gt;{{ category.name }}&lt;/a&gt;&lt;/li&gt;
        {% endfor %}
      &lt;/ul&gt;
    &lt;/div&gt;
  {% endblock %}
  </code></pre>
  
  <p>This is probably a newbie question but is it possible to something like this without creating an app?</p>
  
  <p><strong><code>*EDIT 1*</code></strong></p>
  
  <p>These are my app files, I'll admit this is probably junk, I have tried so many edits from so many different posts I'm sure I've broke it somewhere :P. I was going to remove it and start fresh but I figure I might as well post it to see where I might have gone wrong?</p>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>from django.shortcuts import render_to_response
  from categories.models import categoryList
  
  
  def index(request):
      categories = categoryList.objects.all()
      extra_context = {"categories": categories}
  
      return render_to_response("myapp/index.html", extra_context)
  </code></pre>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>from django.db import models
  
  
  class categoryList(models.Model):
      #id = models.IntegerField(unique=True, db_column='ID') # Field name made lowercase.
      name = models.CharField(max_length=255L, unique=True)
      base_url = models.CharField(max_length=255L, unique=True)
      thumb = models.CharField(max_length=1L, unique=True, blank=True)
      class Meta:
          db_table = 'mysite_categories'
  </code></pre>
  
  <p><strong>index.html</strong></p>
  
  <pre><code>{% if error_message %}&lt;p&gt;&lt;strong&gt;{{ error_message }}&lt;/strong&gt;&lt;/p&gt;{% endif %}
  
  &lt;div class="section" style="float: right;"&gt;
    &lt;h4 class="gradient"&gt;Category List&lt;/h4&gt;
    &lt;ul&gt;
      {% for category in categories %}
        &lt;li&gt;&lt;a href="" id="nav_font"&gt;{{ category.title }}&lt;/a&gt;&lt;/li&gt;
      {% endfor %}
    &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>As mentioned, it's probably junk at this point, if any of you can help me straighten this out it would be appreciated!</p>
  
  <p><strong><code>*EDIT 2*</code></strong></p>
  
  <p><strong>base_right_panel.html</strong></p>
  
  <pre><code>{% block content %}
    &lt;div style="float: right;"&gt;
      &lt;div id="base_categories" style="margin: 10px; padding-bottom: 10px;"&gt;
        {% block base_categories %}
          {% include "base_categories.html" %}
        {% endblock %}
      &lt;/div&gt;
    &lt;/div&gt;
  {% endblock %}
  </code></pre>
  
  <p><strong><code>*Edit 3*</code></strong></p>
  
  <p><strong>base_categories.html</strong></p>
  
  <pre><code>{% block content %}
    &lt;div class="section" style="float: right;"&gt;
      &lt;h4 class="gradient"&gt;Category List&lt;/h4&gt;
      &lt;ul&gt;
        {% if categories %}
          {% for category in categories %}
            &lt;li&gt;&lt;a href="" id="nav_font"&gt;{{ category.title }}&lt;/a&gt;&lt;/li&gt;
          {% endfor %}
        {% else %}
          &lt;p&gt;no data! {{ categories|length }}&lt;/p&gt;
        {% endif %}
      &lt;/ul&gt;
    &lt;/div&gt;
  {% endblock %}
  </code></pre>
  
  <p><strong><code>*EDIT 4*</code></strong></p>
  
  <p>(Application name was changed to CategoryList)</p>
  
  <p><strong>CategoryList/views.py</strong></p>
  
  <pre><code>from django.views.generic import TemplateView
  from CategoryList.models import CategorylistCategorylist #&lt;-- Changed to match inspectdb result
  
  class IndexView(TemplateView):
      template_name="categorylist.html" #&lt;-- Changed name from index.html for clarity
  
      def get_context_data(self, **kwargs):
          context = super(IndexView, self).get_context_data(**kwargs)
          context["categories"] = CategorylistCategorylist.objects.all()
          return context
  </code></pre>
  
  <p><strong>CategoryList/models.py</strong></p>
  
  <pre><code>from django.db import models
  
  class CategorylistCategorylist(models.Model): #&lt;-- Changed to match inspectdb
      id = models.IntegerField(primary_key=True)
      name = models.CharField(max_length=255L, unique=True)
      base_url = models.CharField(max_length=255L, unique=True)
      thumb = models.ImageField(upload_to="dummy", blank=True) #&lt;-- Ignored inspectdb's suggestion for CharField
  
      def __unicode__(self):
          return self.name
  
      # Re-added Meta to match inspectdb
      class Meta:
          db_table = 'categorylist_categorylist'
  </code></pre>
  
  <p><strong>CategoryList/urls.py</strong></p>
  
  <pre><code>from django.conf.urls.defaults import patterns, url, include
  from django.contrib import admin
  from django.conf import settings
  from CategoryList import views
  
  admin.autodiscover()
  
  urlpatterns = patterns('',
      url(r'^$', views.IndexView.as_view(), name='categorylist'),
  )
  
  if settings.DEBUG:
      urlpatterns = patterns('',
      url(r'^media/(?P&lt;path&gt;.*)$', 'django.views.static.serve',
          {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
      url(r'', include('django.contrib.staticfiles.urls')),
  ) + urlpatterns
  </code></pre>
  
  <p><strong>MySite/urls.py</strong></p>
  
  <pre><code>from django.conf.urls import patterns, include, url
  from django.contrib import admin
  from django.conf import settings
  from home import views as home_view
  from CategoryList import views as index_view
  
  admin.autodiscover()
  
  urlpatterns = patterns('',
      url(r'^$', home_view.HomeView.as_view(), name="home"),
  
      url(r'^categories/$', index_view.IndexView.as_view(), name='categorylist'),#include('CategoryList.urls')),
  
      url(r'^admin/', include(admin.site.urls)),
      #url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
  )
  
  if settings.DEBUG:
      urlpatterns = patterns('',
      url(r'^media/(?P&lt;path&gt;.*)$', 'django.views.static.serve',
          {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
      url(r'', include('django.contrib.staticfiles.urls')),
  ) + urlpatterns
  </code></pre>
  
  <p>So far I can load the url "<em>localhost:8000/categories</em>" and I will see the list of category names appear on the right side of the screen as expected, but there is no template formatting applied. Inside my "*base_right_panel.html*" file I've tried "<em>{% include "categorylist.html %}</em>" to link directly to the application, which displays the correct template formatting, but displays the "<em>{% else %}</em>" response from "<em>{% if categories %}</em>" instead of the categories? I have tried changing the include to point to "<em>categories/</em>", which works in the browser, but it tells me it cannot find the template? </p>
  
  <p>I'm sooo stumped right now..?</p>