---
title: "Django"
author: "xserver"
date: "2013-03-03T20:04:12Z"
tags: []
categories: ["编程语言"]
slug: "django"
draft: false
lastmod: "2013-03-14T15:50:38Z"
id: 1820630
url: "https://xserver.iteye.com/blog/1820630"
---

<https://docs.djangoproject.com/en/1.5/#django-documentation>

<https://docs.djangoproject.com/en/1.5/topics/>

<https://docs.djangoproject.com/en/1.5/intro/overview/#>

老老实实看文档，快不了。
OMG，发现中文教程，版本<1.5。可以帮助理解
<http://code.google.com/p/docs-django-zh-cn/wiki/IntroTutorial02>


--编码问题、中文
http://blog.sina.com.cn/s/blog_4560e10e0101gdkh.html

--Begin
import django; print(django.get_version())

--Creating a project
django-admin.py startproject mysite
顶层project name 可以随便改，这里是叫mysite

--Where should this code live?
不要放到www下面，那是不安全的，放到home/Web/
urls.py、wsgi.py的作用

--Run Your Site
python manage.py runserver

--Database setup
python manage.py syncdb

--Django Model
 it’s been solving two years’ worth of database-schema problems. 
A写model类：继承models.Model
B打印SQL：python manage.py sql polls
C将模型同步到DB：python manage.py syncdb
D进入django的shell：python manage.py shell

--def __unicode__(self)
添加此方法后，要重申进入 python manage.py shell
打印自己，Why __unicode__() and not __str__()?

part 1. 学习使用Django那套Model API

------------------------------------------------------------

part 2.  讲述后台管理与模型

------------------------------------------------------------

Part 3. urls与view，url的命名空间，template

------------------------------------------------------------

Part 4.
------------------------------------------------------------

Part 5. 自动化测试

------------------------------------------------------------

--Django urls
<http://grasshopperpebbles.com/django-python/how-to-set-up-a-home-page-with-django/>

任意字符 .*
(regular expression, Python callback function )

urlpatterns += patterns('', ...)


------------------------------------------------------------

--Django static files
在官方文档里看Handling static files，图片出不来，蛋痛。
现在还没高清那settings.py中的目录作用，后来参考这个，图片显示出来了。
<http://blog.csdn.net/wenxuansoft/article/details/8580508>
肯定还有别的方法。。。

MEDIA_ROOT：用户上传使用；MEDIA_URL：和urls.py 中的配置有关系吗？
STATIC_ROOT：静态文件；STATIC_URL：
STATICFILES_DIRS：Additional locations of static files


--Django Template
<http://www.cnblogs.com/btchenguang/archive/2012/09/05/2672364.html>