django保证主要版本的向后兼容,也就是说你在django1.1上开发的应用,可以在1.2、1.3、1.9等所有以1开头的版本,但是到了2你的应用可能不再兼容,需要重写;这与python的兼容策非常的相似;

 

from django.db import models


class Book(models.Model):
    name = models.CharField(max_length=50)
    pub_date = models.DateField

###########################################
from django.shortcuts import render_to_response
from models import Book


def latest_books(request):
    book_list = Book.objects.order_by('-pub_date')[:10]
    return render_to_response('latest_books.html',{'book_list':book_list})


###########################################
from django.conf.urls.defaults import *
import views


urlpatterns = patterns(r'^latest$/',views.latest_books)


###########################################
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Books</title>
</head>
<body>
    <h1>Books</h1>
    <ul>
        {% for book in book_list %}
        <li>{{ book.name }}</li>
        {% end for %}
    </ul>
</body>
</html>

 

posted on 2016-09-11 17:09  神圣兽国窝窝乡独行侠  阅读(126)  评论(0编辑  收藏  举报