开发者

Import other Django Apps models into View - should be basic

I realise I'm doing something basic wrong here, just not sure what it is. I'm not getting any errors, but I'm not getting any of the model data displayed when I load the page.

Here's what I'm trying to do: Apps: base, blog, resume

I'm trying to get the models from blog and resume to show up in the view of base. Both the blog and resume apps work fine on their own.

base/views.py

from django.core.urlresolvers import reverse
from django.shortcuts import render_to_response
from testpro.blog.models import Post
from 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>
            {% for 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>
            {% for 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 the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    (r'^main/', 'base.views.main'),
    (r'^admin/', include(admin.site.urls)),
)

What stupid mistake am I making? The template renders, it just doesn't开发者_C百科 contain any 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>


{% for project in projects.object_list %}
# should be
{% for project in projects %}

and

{% for post in posts.object_list %}
# should be
{% for post in posts %}

QuerySets don't have an object_list attribute I'm aware of, so the template engine is silently failing on it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜