Django Firstofhexu
Upcoming SlideShare
Loading in...5
×
 

Django Firstofhexu

on

  • 1,026 views

django && myproject introduction

django && myproject introduction

Statistics

Views

Total Views
1,026
Views on SlideShare
1,026
Embed Views
0

Actions

Likes
1
Downloads
2
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Hello! My name is Jason Davies; I'm a freelance Web developer from Cambridge and I've been using Django for about 2 years ever since it was open-sourced in July 2005. Hopefully this will give you a good introduction to the basics of Django. Simon Willison will cover even more stuff in the advanced tutorial.
  • Django is named after the gypsy jazz guitarist, Django Reinhardt.
  • Django was released publicly under a BSD license in July 2005.
  • The Django project website is packed full of useful information.
  • The first time you run Django, you need to create a “project”. A project is essentially a collection of settings for an instance of Django: including database configuration, Django-specific options and application-specific settings.
  • It worked!
  • Typically, an app exists to solve a single problem.

Django Firstofhexu Django Firstofhexu Presentation Transcript

  • && danaweb [email_address]
  • Django Reinhardt
  • www.djangoproject.com
  •  
  • 特性
    • 对象相关的映射:
    • 完全在 Python 中定义你的数据模型。你可以免费得到一个丰富的,动态访问数据库的 API --但如果需要你仍然可以写 SQL 语句。
    • URL :
    • URL 的设计漂亮, cruft-free ,没有框架的特定限定。象你喜欢的一样灵活。
    • 模版系统:
    • 使用 DjanGo 强大而可扩展的模板语言来分隔设计、内容和 Python 代码。
    • 自动化的管理界面 :
    • 不需要你花大量的工作来创建人员管理和更新内容的接界。 Django 可以自动完成。
    • 支持多种数据库:
    • 已经支持 Postgresql, MySql, Sqlite3, Oracle, ado_mssql
    • 国际化:
    • 完全支持多国语言,允许针对应用程序提供特定国家语言的翻译字符
  • 优点 入门快 开发速度快 统一的约定
  • 缺点 当前版本不支持多数据库 模板引擎的性能较差 文档 ... 口口相传
  • 3部曲 django-admin.py startproject myproject django-admin.py startapp myapp 编写 urls , views
  • “Projects” $ django-admin.py startproject myproject
  • myproject/ __init__.py manage.py settings.py urls.py
  • $ python manage.py runserver Validating models... 0 errors found. Django version 0.96-pre, using settings 'myproject.settings' Development server is running at http://127.0.0.1:8000/ Quit the server with CONTROL-C.
  •  
  • “Apps” $ django-admin.py startapp blog
  • myproject/ blog/ __init__.py models.py views.py __init__.py manage.py settings.py urls.py
  • 基本流程
  • 该后台管理了
  • 创建模型 from django.db import models class View(models.Model): cname = models.CharField(' 中文名 ', max_length=100) dataset = models.ForeignKey(DataSet, help_text=' 数据集 ') view_type = models.CharField(' 视图类型 ', choices=VIEW_TYPE, max_length=1) time_type = models.CharField(' 时间类型 ', choices=TIME_CHOICES, max_length=1) prov_type = models.CharField(' 省维度数据源 ',choices=DATASET_PROVINCE,max_length=20) country_type = models.CharField(' 国维度数据源 ',choices=DATASET_COUNTRY,max_length=20) select_date = models.CharField(' 默认日期 ',choices=SELECT_DATE,max_length=1,default=&quot;1&quot;) #max_length = models.IntegerField(' 最大展示数量 ',default=&quot;1000&quot;,help_text=&quot; 页面上展示的数据最行数 &quot;,blank=True) #count_sum = models.BooleanField(' 计算合计 ') explain = models.TextField(&quot; 简介 &quot;, default='', blank=True ,help_text=&quot;<font color='red'> 提示 </font> :用 &lt;br&gt; 换行 &quot;)
  • 同步表结构 $ python manage.py syncdb Creating table danaweb_view Loading 'initial_data' fixtures...
  • 管理界面 Django Admin from django.contrib import admin class ViewAdmin(admin.ModelAdmin): &quot;&quot;&quot; fieldsets = fieldsets = ( (None, { 'fields': (('cname', 'view_type', 'dataset'), 'body') }), ) &quot;&quot;&quot; list_filter = ('view_type','time_type','select_date') list_display = (&quot;cname&quot;,&quot;time_type&quot;,'dataset') search_fields = ['cname', 'time_type'] admin.site.register(View, ViewAdmin)
  •  
  •  
  • 2个库 配置库 danacfg 数据库 dana danaweb数据结构
  • danacfg
    • auth_group
    • auth_group_area
    • auth_group_permissions
    • auth_group_view
    • auth_message
    • auth_permission
    • auth_user
    • auth_user_groups
    • auth_user_user_permissions
    • danaweb_area
    • danaweb_city
    • danaweb_dataset
    • danaweb_datasetcolumn
    • danaweb_flashurl
    • danaweb_useraction
    • danaweb_userdimension
    • danaweb_view
    • django_admin_log
    • django_content_type
    • django_session
    • django_site
  • 数据集
      danaweb_dataset 存表名,建表语句 ForeignKey danaweb_datasetcolumn 存字段
    ForeignKey
  • 视图
      danaweb_view danaweb_dataset
      ForeignKey
  • 注意事项与约定 条件: 日报的类型用日历 周报月报用单选框 关联的格式: 字典文件名 | 列 | 对应字段 1, 对应列 ; 对应字段 2, 对应列 维度: 如果有省、时间,要将“默认维度”勾选 指标: 可以聚合的字段,勾选“千分位” 对齐拦:时间“居中”,维度“左对齐”,指标“右对齐” 配置数据集的时候要注意关键字段的名字: 省编码 province , 省名称 provname , 市编码 city , 市名称 cityname 开始时间 begin_date , 结束时间 end_date
  • 谢谢