zoukankan      html  css  js  c++  java
  • Django~NewProject and APP

    New Project

    1.新建 django-admin startproject mysite

    2.运行 manage.py runserver 8080

    New APP

    1.manage.py startapp polls

    2.write view.py:  def index 等等

    image

    3.create urls.py:  urlpatterns=[  url() ]

    image

    4.url链接到project中:修改添加mysite/urls.py,

    url(r'^polls/', include('polls.urls')), 

    image

    5.安装数据库 manage.py migrate

    6.creating models 

    image

    7.Activating models 在mysite/settings.py 中添加一行

    image

    8创建编译 manage.py makemigrationgs polls

    image

    修改编译manage.py migrate

    image

    9运作,输入数据

    manage.py shell

    import django

    django.setup()

    -------------

    from polls.models import Question,Choice

    Question.objects.all()

    from django.utils import timezone

    q = Question(question_text="What's new?", pub_date=timezone.now())

    image

    More Vies

    1.vies.py 新增 def detail results vote

    2.polls/urls.py新增url

    添加模板Template

    1.在APP的文件下新建template/app/index.html

    2.编辑html文件

    3.更新polls/views.py

    New 2 APPS

    1.manage.py startapp polls2,在project中添加注册

    2.copy polls 的templates,新建文件夹修改app name

    3.copy修改models,

    4.修改urls.

    5.修改views

    主要所有polls修改为polls2

    urls.py中的app_name

    views.py中的好多

    还有xxx.html中的

    Make the poll app modifiable in the admin¶

    polls2/admim.py 中添加model

    from django.contrib import admin
    
    from .models import Question
    
    admin.site.register(Question)
    

    ListView and DetailView

    We’re using two generic views here: ListView and DetailView. Respectively, those two views abstract the concepts of “display a list of objects” and “display a detail page for a particular type of object.”

    通用视图

    除了object_list外,Django还提供了许多通用视图函数,分布在几个模块中:

    django.views.generic.list_detail模块
    • object_list      显示模型对象列表   
    • object_detail  显示单个模型对象
    django.views.generic.create_update模块
    • create_object    创建模型对象
    • update_object   修改模型对象
    • delete_object    删除模型对象
    django.views.generic.simple模块
    • direct_to_template   直接使用指定的模板渲染给定的context对象
    • redirect_to   重定向到指定的url
    django.views.generic.date_based模块

    这个模块主要处理“按时间查看存档”的功能,来源于新闻出版行业。具体包括:

    • archive_index   最顶级的归档,列出所有年份及指定数量的最新对象
    • archive_year     按年归档,列出所有拥有对象的月份
    • archive_month   按月归档,列出本月的所有对象,找到拥有对象的上一个、下一个月份
    • archive_week     按周归档,列出本周的所有对象
    • archive_day     按日归档,列出当天的所有对象,找到拥有对象的上一个、下一个日期
    • archive_today     当前日期(今天)的按日归档
    • object_detail     显示按照年/月/日/序号找到的对象
    三年有成,问苍茫~
  • 相关阅读:
    Attach Files to Objects 将文件附加到对象
    Provide Several View Variants for End-Users 为最终用户提供多个视图变体
    Audit Object Changes 审核对象更改
    Toggle the WinForms Ribbon Interface 切换 WinForms 功能区界面
    Change Style of Navigation Items 更改导航项的样式
    Apply Grouping to List View Data 将分组应用于列表视图数据
    Choose the WinForms UI Type 选择 WinForms UI 类型
    Filter List Views 筛选器列表视图
    Make a List View Editable 使列表视图可编辑
    Add a Preview to a List View将预览添加到列表视图
  • 原文地址:https://www.cnblogs.com/lynclynn/p/5216818.html
Copyright © 2011-2022 走看看