Django Project 12

Source: Internet
Author: User

Preparations [plain] service mysqld start create database web11 default charset utf8; django-admin.py startproject web12 django-admin.py startapp news templates create admin. create settings [python] DATABASES = {'default': {'Engine ': 'django. db. backends. mysql ', 'name': 'web12', 'user': 'root', 'Password': '', 'host':'', 'Port ': '', }} INSTALLED_APPS = ('django. contrib. auth ', 'django. contrib. contenttypes ', 'dja Ngo. contrib. sessions ', 'django. contrib. sites ', 'django. contrib. messages ', 'django. contrib. staticfiles ', 'News', 'django. contrib. admin ',) models [python] from django. db import models class Author (models. model): name = models. charField (max_length = 20) def _ unicode _ (self): return self. name class Book (models. model): name = models. charField (max_length = 20) authors = models. manyToManyField (Author) def _ _ Unicode _ (self): return self. name views [python] # coding: utf8 from blog. models import Author, Book from django. shortcuts import render_to_response books = Book. objects. all () authors = Author. objects. all () def show (req): return render_to_response('show.html ', {'books': books, 'authors ': authors}) def book (req, book_id): book = Book. objects. get (id = book_id) return render_to_response('show.html ', {'books': bo Oks, 'book': book, 'authors ': authors}) def author (req, author_id): author = Author. objects. get (id = author_id) return render_to_response('show.html ', {'authors': authors, 'author': author, 'books ': books}) urls [python] from django. conf. urls. defaults import patterns, include, url from django. contrib import admin. autodiscover () urlpatterns = patterns ('', url (R' ^ author/(\ d {1, 5})/$ ', 'blog. views. author '), ur L (R' ^ book/(\ d {1, 5})/$ ', 'blog. views. book '), url (R' ^ show/$', 'blog. views. show '), url (R' ^ admin/', include (admin. site. urls),) base [html] "UTF-8"?> <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Strict // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.