Python&Django配置php
Django官方主页:www.djangoproject.comhtml
开发IDE,我的倾向于PyCharm,在这里能够快速的学习到一些Django使用技巧。python
要想回答这个问题,首先要了解Django项目的结构。Django项目采用“项目(project)-应用(app)-模块(module)”的两级结构,其中app是一个实现某种功能的web程序,有本身的数据模型、视图、模板等。也就是说一个project能够包含多个app,一个app也能够在多个项目中使用。若是以为本身写的app有必定的通用性,也能够将其发布。常见的Django第三方app有不少,能够从官方wiki(连接)上找。web
admin应用指的是django自带的admin应用,它的路径是django.contrib.admin,sql
利用它能够自动生成后台管理界面,这也是Django强大的地方之一(我的以为还有一点是部署方便,创建一个demo网站只须要python + django + runserver + sqlite3基本上能够搞定全部东西,没必要想php同样装服务器什么)。在《The Django Book》对admin的描述是这样的:django
For a certain class of Web sites, an admin interface is an essential part of the infrastructure. This is a Web-based interface, limited to trusted site administrators, that enables the adding, editing and deletion of site content. Some common examples: the interface you use to post to your blog, the backend site managers use to moderate user-generated comments, the tool your clients use to update the press releases on the Web site you built for them.服务器
There’s a problem with admin interfaces, though: it’s boring to build them. Web development is fun when you’re developing public-facing functionality, but building admin interfaces is always the same. You have to authenticate users, display and handle forms, validate input, and so on. It’s boring, and it’s repetitive.并发
So what’s Django’s approach to these boring, repetitive tasks? It does it all for you – in just a couple of lines of code, no less. With Django, building an admin interface is a solved problem.app
This chapter is about Django’s automatic admin interface. The feature works by reading metadata in your model to provide a powerful and production-ready interface that site administrators can start using immediately. Here, we discuss how to activate, use, and customize this feature.less
(译文):
对于某一类网站,管理界面是基础设施中很是重要的一部分。 这是以网页和有限的可信任管理者为基础的界面,它可让你添加,编辑和删除网站内容。 一些常见的例子:你能够用这个界面发布博客,后台的网站管理者用它来润色读者提交的内容,你的客户用你给他们创建的界面工具更新新闻并发布在网站上,这些都是使用管理界面的例子。
可是管理界面有一问题:建立它太繁琐。当你开发对公众的功能时,网页开发是有趣的,可是建立管理界面一般是千篇一概的。 你必须认证用户,显示并管理表格,验证输入的有效性诸如此类。 这很繁琐并且是重复劳动。
Django 在对这些繁琐和重复的工做进行了哪些改进?它用不能再少的代码为你作了全部的一切。Django 中建立管理界面已经不是问题。
这一章是关于 Django 的自动管理界面。这个特性是这样起做用的: 它读取你模式中的元数据,而后提供给你一个强大并且可使用的界面,网站管理者能够用它当即工做。
使用admin应用只须要如下几个步骤:
[settings/urls]配置相关的urls.py和settings.py,这一步一般是注释相关代码
[models]定义本身的model
[admin]为每个model写一个ModelAdmin,并自定义本身的行为、UI、逻辑。
[admin]将ModelAdmin和model关联,使用admin.site.register方法
1.4 The Django Book
《The Django Book》在线文档