Import other Django Apps models into View - should be basic -
i realise i'm doing basic wrong here, not sure is. i'm not getting errors, i'm not getting of model data displayed when load page.
here's i'm trying do: apps: base, blog, resume
i'm trying models blog , resume show in view of base. both blog , resume apps work fine on own.
base/views.py
from django.core.urlresolvers import reverse django.shortcuts import render_to_response testpro.blog.models import post testpro.resume.models import project def main(request): """main listing.""" posts = post.objects.all().order_by("-created") projects = project.objects.all().order_by("-created") return render_to_response("list.html", dict(posts=posts, projects=projects, user=request.user))
list.html template
{% extends "bbase.html" %} {% block content %} <div class="main"> <h3>blog posts</h3> <!-- posts --> <ul> {% post in posts.object_list %} <div class="title">{{ post.title }}</div> <ul> <div class="time">{{ post.created }}</div> <div class="body">{{ post.body|linebreaks }}</div> </ul> {% endfor %} </ul> <!-- projects --> <h3>projects</h3> <ul> {% project in projects.object_list %} <div class="title">{{ project.title }}</div> <ul> <div class="industry">{{ project.industry }}</div> <div class="time">{{ project.created }}</div> <div class="body">{{ project.body|linebreaks }}</div> </ul> {% endfor %} </ul> </div> {% endblock %}
finally, urls.py
from django.conf.urls.defaults import * # uncomment next 2 lines enable admin: django.contrib import admin admin.autodiscover() urlpatterns = patterns('', (r'^main/', 'base.views.main'), (r'^admin/', include(admin.site.urls)), )
what stupid mistake making? template renders, doesn't contain model data.
edit: added bbase.html template
<?xml version="1.0" encoding="utf-8"?> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>{% block title %}test project{% endblock %}</title> </head> <body> <div id="sidebar"> {% block sidebar %} {% endblock %} </div> <div id="container"> <div id="menu"> {% block nav-global %} <!-- menu --> <h3>myblog</h3> {% if user.is_staff %} <a href="{% url admin:index %}">admin</a> <a href="{% url admin:blog_post_add %}">add post</a> {% endif %} {% endblock %} </div> <div id="content"> {% block content %}{% endblock %} </div> </div> </body> </html>
{% project in projects.object_list %} # should {% project in projects %}
and
{% post in posts.object_list %} # should {% post in posts %}
queryset
s don't have object_list
attribute i'm aware of, template engine silently failing on it.
Comments
Post a Comment