欢迎大家赞助一杯啤酒🍺 我们准备了下酒菜:Formal mathematics/Isabelle/ML, Formal verification/Coq/ACL2/Agda, C++/Lisp/Haskell
Django
来自开放百科 - 灰狐
(版本间的差异)
第129行: | 第129行: | ||
python manage.py runserver | python manage.py runserver | ||
http://local:8000/admin/ | http://local:8000/admin/ | ||
+ | ==use Django with Lighttpd== | ||
+ | ==use Django with Apache== | ||
+ | edit your httpd.conf | ||
+ | <Location "/mysite/"> | ||
+ | SetHandler python-program | ||
+ | PythonHandler django.core.handlers.modpython | ||
+ | SetEnv DJANGO_SETTINGS_MODULE mysite.settings | ||
+ | PythonDebug On | ||
+ | </Location> | ||
+ | http://localhost/mysite/ | ||
+ | ==use Django with FastCGI== | ||
==成功应用== | ==成功应用== |
2007年2月3日 (六) 11:23的版本
Django: The Web framework for perfectionists with deadlines
Django 是一个高级 Python web framework,它鼓励快速开发和干净的、MVC设计。它包括一个模板系统,对象相关的映射和用于动态创建管理界面的框架。Django遵守BSD版权。
目录 |
特性
- 对象相关的映射
完全在Python中定义你的数据模型。你可以免费得到一个丰富的,动态访问数据库的API--但如果需要你仍然可以写SQL语句。
- URL 分发
URL的设计漂亮,cruft-free,没有框架的特定限定。象你喜欢的一样灵活。
- 模版系统
使用DjanGo强大而可扩展的模板语言来分隔设计、内容和Python代码。
- Cache系统
可以挂在内存缓冲或其它的框架实现超级缓冲 -- 实现你所需要的粒度。
- 自动化的管理界面
不需要你花大量的工作来创建人员管理和更新内容的接口。DjanGo可以自动完成。
- 支持多种数据库
已经支持Postgresql, MySql, Sqlite3, Oracle, ado_mssql
相关链接
- http://www.djangoproject.com/
- 下载 - http://download.huihoo.com/python/framework/django/
- http://wiki.woodpecker.org.cn/moin/DjanGo
- Django-powered sites - http://code.djangoproject.com/wiki/DjangoPoweredSites
安装指南
First, download Django-0.95.tar.gz. Then:
tar xzvf Django-0.95.tar.gz cd Django-0.95 sudo python setup.py install // 会去下载相关 egg 包,egg与Java jar 类似,包含版本化的包和依赖性管理 cd /var/www django-admin.py startproject mysite cd mysite python manage.py runserver http://localhost:8000
创建一个poll应用
python manage.py startapp polls vi polls/models.py from django.db import models
class Poll(models.Model): question = models.CharField(maxlength=200) pub_date = models.DateTimeField('date published')
class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(maxlength=200) votes = models.IntegerField()
vi polls/settings.py INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'mysite.polls' )
创建数据库
mysql>create database pool
vi settings.py DATABASE_ENGINE = 'mysql' DATABASE_NAME = 'poll' DATABASE_USER = 'root' DATABASE_PASSWORD = DATABASE_HOST = 'localhost' DATABASE_PORT = '3306'
python manage.py syncdb python manage.py sql polls
BEGIN; CREATE TABLE `polls_poll` ( `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `question` varchar(200) NOT NULL, `pub_date` datetime NOT NULL ); CREATE TABLE `polls_choice` ( `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `poll_id` integer NOT NULL REFERENCES `polls_poll` (`id`), `choice` varchar(200) NOT NULL, `votes` integer NOT NULL ); COMMIT;
可看到在mysql中已经创建了相关表
mysql> show tables; +----------------------------+ | Tables_in_poll | +----------------------------+ | auth_group | | auth_group_permissions | | auth_message | | auth_permission | | auth_user | | auth_user_groups | | auth_user_user_permissions | | django_content_type | | django_session | | django_site | | polls_choice | | polls_poll | +----------------------------+ 12 rows in set (0.00 sec)
python manage.py shell >>> from mysite.polls.models import Poll, Choice >>> Poll.objects.all() [] >>> from datetime import datetime >>> p = Poll(question="What's up?", pub_date=datetime.now()) >>> p.save() >>> p.id 1L >>> p.question "What's up?" >>> p.pub_date datetime.datetime(2006, 9, 1, 15, 8, 1, 135114)
Django admin site默认没有激活,可通过以下三个步骤激活它
1. Add "django.contrib.admin" to your INSTALLED_APPS setting in settings.py 2. Run python manage.py syncdb 3. vi urls.py
python manage.py runserver http://local:8000/admin/
use Django with Lighttpd
use Django with Apache
edit your httpd.conf
<Location "/mysite/"> SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE mysite.settings PythonDebug On </Location> http://localhost/mysite/
use Django with FastCGI
成功应用
国外
- Arch Linux - main website for the Arch Linux distribution
- MisterApe.com - Games portal
- rPapers - The easy way to share your working papers and published articles.
- PediaPress.com - Print-on-demand service for individual books based on Wikipedia articles.
- trogger.info - Your Internet Travel Community
- Tabblo - Photo sharing site with a narrative twist. Full online photo editing and page construction.
- Solaris Counter - This is a simple counter for OpenSolaris/Solaris? users.
- parsed.org - A computing tips site.
- Diskbot - Disk Management webapp written in Django
- Photogallery - A photo gallery system
- worldinpictures.org - Enter any worldwide location, see pictures of it (from Flickr).
国内
分享您的观点