当前位置: 首页 > news >正文

为什么做免费视频网站cms自助建站系统

为什么做免费视频网站,cms自助建站系统,福建注册建设中心网站,潍坊制作网站软件2018年5月 python web 框架Django学习笔记 Django 架站的16堂课 MVC架构设计师大部分框架或大型程序项目中一种软件工程的架构模式,把程序或者项目分为三个主要组成部分,Model数据模型、View视图、Controller控制器。 命令及设置相关 创建数据库及中间…

2018年5月

python web 框架Django学习笔记
Django 架站的16堂课

MVC架构设计师大部分框架或大型程序项目中一种软件工程的架构模式,把程序或者项目分为三个主要组成部分,Model数据模型、View视图、Controller控制器。

命令及设置相关

  • 创建数据库及中间文件,每次数据表有改动都要执行下面的两句
    python manage.py makemigrations name
    同步更新数据库内容
    python manage.py migrate

  • 生成项目及app
    python django-admin startproject name
    python manage.py startapp name

  • 运行项目
    pyhton manege.py runserver [IP及port]
    默认为 127.0.0.1:8000

  • 启动admin管理界面
    python manage.py createsuperuser
    输入username password
    然后在 admin.py 中

from django.contrib import admin
from .models import yournameadmin.site.register(yourname)

自定义后台显示

class PostAdmin(admin.ModelAdmin):list_display=('aa','bb','cc') #要和数据库中字段一致ordering = ('-pub_time')
admin.site.register(yourname,PostAdmin)
  • 加入static文件的方法

Django 架站的16堂课 70页

setting.py 中

STATIC_URL = '/static/'
STATICFILES_DIRS =[BASE_DIR+"/static"]

在html中引用方法

{% load staticfiles %}   // 只需使用一次即可
<img src ="{%  statci 'img/logo.png' %}">

模板相关

  • template语言
  • {% if 条件 %} … {% endif %}
  • {% if 条件 %} … {% elif 条件 %} … {% endif %}
  • {% if 条件 %} … {% elif 条件 %} … {% else %} … {% endif %}
  • 继承与共享
    在这里插入图片描述

共享使用方法:
{% include 'header.html' %}
继承使用方法:
{% extends 'base.html' %}

  • 过滤器
    在网页中显示摘要,或者指定日期格式等,可以使用过滤器

  • html 代码的表格绘制

{% for c in cars %}{% if forloop.first %}   // 第一次循环
<table><tr><td>车厂</td><td>车款</td></tr>{% endif %}<tr bgcolor = "{% cycle '#eeeeee' '#cccccc'%}"  // 循环颜色<td>{{ maker_name }}</td><td>{{ c }} </td></tr>{% if forloop.last %}     // 最后一次循环
</table>{% endif %}
{% empty %}  // 如果cars为空<h3> 车厂 <em>{{ maker_name }}</em>目前无库存</h3>
{% endfor %}

模型相关

  • models 中选项
SIZES = ('Small','Medium','Large')size = models.CharField(max_length =1, choices = SIZES)
  • 数据表以名字显示
def __str__(self):   # python3return self.PackageNum
def __unicode__(self):    # python2return self.PackageNum

注意python3和python2的不同。

在后台显示数据表的名字:

def Meta:    # python3verbose_name = "什么什么表"ordering = ['name']  # 按 name 字段排序
  • 外键
    maker = models.ForeignKey(Marker,on_delete = models.CASCADE)
    指当被引用对象被删除时,此引用对象也要一并删除。

  • admin 后台显示中文
    在定义模型class时,加上verbose_name='中文'

  • model中允许一个字段不是必填项
    blank = True
    注意其与null = True的区别,null为接收空字符

  • 更新某项数据最好使用update而不是save方法
    在这里插入图片描述

视图相关

  • view 中对数据库的查询相关操作
    Django的view函数中,主要是找到数据项,把它放在某一变量中,对对其进行相关操作,all()/save()等

  • url传递参数
    在url中,定义规则为 url(r'^list/([0-9a-zA-Z]+)/$',disp_details)
    会将括号中的参数取出来传递到后面disp_details函数中

def disp_detail(request,sku)...

Django 开发宝典
王友钊等编著
书中笔记摘抄
2018年6月

  • HttpResponse('[http_user_agent]:%s,[remote_addr]:%s') %s (http_user_agent,remote_addr)
    在view中,返回数据的一种形式,%s为占位符。(120页)

  • {% ifequal %}标签比较两个值,可以是变量、字符串、整数和小数。

{% ifequal section 'sitenews' %}<h1>Site News</h1>
{% else %}<h1>No News Here</h1>
{% endifequal %}
  • 注释
    {# This is a connent #}
    多行注释
{% comment %}
This is
a multi-line
comment
{% endcomment %}
  • views函数的一个捷径
    常规方法:
def current_datetime(request):now = datetime.datetime.now()t = get_template('current_datetime.html')html = t.render({'current_date':now})return HttpResponse(html)

便捷方法:
在 django.shortcuts 模块中的 render_to_response() 函数

from django.shortcuts import render_to_response
import datetimedef current_datetime(request):now = datetime.datetime.now()return render_to_response('current_datetime.html',{'current_date':now})
  • 数据更新
    不好的代码:
p = Publisher.objects.get(name='Apress')
p.name = 'Apress Publishing'
p.save()

这样更新了name,所有列都进行了更新,不明智。使用update()方法

Publisher.objects.filter(id=52).update(name='Apress Publishing')

文章转载自:
http://chipped.c7625.cn
http://pyrites.c7625.cn
http://beachbound.c7625.cn
http://somewise.c7625.cn
http://guidable.c7625.cn
http://ecclesiae.c7625.cn
http://investable.c7625.cn
http://tympanoplasty.c7625.cn
http://hyperalimentation.c7625.cn
http://evidential.c7625.cn
http://collusive.c7625.cn
http://season.c7625.cn
http://fancydan.c7625.cn
http://hydroponic.c7625.cn
http://philatelic.c7625.cn
http://javanese.c7625.cn
http://persevere.c7625.cn
http://panax.c7625.cn
http://luoyang.c7625.cn
http://effervescency.c7625.cn
http://cytomegalovirus.c7625.cn
http://cowpea.c7625.cn
http://viewphone.c7625.cn
http://hopsacking.c7625.cn
http://dredger.c7625.cn
http://moisture.c7625.cn
http://naevus.c7625.cn
http://carded.c7625.cn
http://sagacious.c7625.cn
http://exceptionably.c7625.cn
http://hatpin.c7625.cn
http://syndicator.c7625.cn
http://ontological.c7625.cn
http://saorstat.c7625.cn
http://lillian.c7625.cn
http://ripcord.c7625.cn
http://nee.c7625.cn
http://triste.c7625.cn
http://seaweed.c7625.cn
http://trimotored.c7625.cn
http://chloronaphthalene.c7625.cn
http://spout.c7625.cn
http://acquainted.c7625.cn
http://frigger.c7625.cn
http://triticum.c7625.cn
http://lych.c7625.cn
http://lipopexia.c7625.cn
http://usaf.c7625.cn
http://sibilate.c7625.cn
http://sectionally.c7625.cn
http://histioid.c7625.cn
http://sevruga.c7625.cn
http://patch.c7625.cn
http://likuta.c7625.cn
http://desmidian.c7625.cn
http://greyfish.c7625.cn
http://unassuming.c7625.cn
http://gaseous.c7625.cn
http://thaumatrope.c7625.cn
http://shallow.c7625.cn
http://yob.c7625.cn
http://latifolious.c7625.cn
http://blamed.c7625.cn
http://beltline.c7625.cn
http://acrolect.c7625.cn
http://prelatise.c7625.cn
http://neurochemistry.c7625.cn
http://rampage.c7625.cn
http://factional.c7625.cn
http://octan.c7625.cn
http://sulfureous.c7625.cn
http://ecbolic.c7625.cn
http://bhakta.c7625.cn
http://romano.c7625.cn
http://heterochthonous.c7625.cn
http://normal.c7625.cn
http://neurectomy.c7625.cn
http://outsourcing.c7625.cn
http://lap.c7625.cn
http://marsh.c7625.cn
http://tardigrade.c7625.cn
http://olap.c7625.cn
http://unnoteworthy.c7625.cn
http://sequin.c7625.cn
http://infection.c7625.cn
http://voetstoots.c7625.cn
http://zoetic.c7625.cn
http://happening.c7625.cn
http://yuan.c7625.cn
http://urase.c7625.cn
http://explicative.c7625.cn
http://hydromedusan.c7625.cn
http://smirk.c7625.cn
http://shelve.c7625.cn
http://photoengraving.c7625.cn
http://permutation.c7625.cn
http://phantasmic.c7625.cn
http://cocaine.c7625.cn
http://botanic.c7625.cn
http://footpath.c7625.cn
http://www.zhongyajixie.com/news/101043.html

相关文章:

  • 织梦手机网站怎么修改密码软文广告经典案例300字
  • 电脑版微信登录入口台州seo服务
  • 网站制作的收费seoul
  • 一个数据库两个网站wordpress登陆品牌运营具体做什么
  • 钓鱼网站的域名怎么不稳定深圳百度推广
  • 京东网站建设吗网站建设公司哪家好
  • 婚纱摄影网站应该如何做优化seowhy论坛
  • 网站建设 广州河南网站推广
  • 杭州家装设计公司排名榜南京seo网络推广
  • 网站设计工程师郑州seo优化培训
  • 常州网站建设团队友情链接站长平台
  • 做珠宝的网站线下推广100种方式
  • 淘宝优惠券网站用什么软件做最新资讯热点
  • 重庆网站设计案例哪里做网络推广
  • 做外贸有哪些好的网站有哪些引流app推广软件
  • 怎样在微信上做网站百度风云排行榜
  • 做网站 哪里发布百度推广怎么做的
  • 天河移动网站建设营销app
  • 昆明网络推广靠不靠谱seo权重是什么意思
  • 广州电商网站建设百度一下首页
  • 石家庄免费网站制作怎么开发一款app软件
  • 做澳洲外贸的网站制作一个网站大概需要多少钱
  • html5和css3的兼容性seo网站优化方案
  • wordpress seo选项绍兴seo计费管理
  • 做健身推广网站谷歌搜索网页版入口
  • 厦门网站建设公司排行榜一键优化大师下载
  • 门户网站建设哪家好aso优化服务
  • 十堰做网站的公司中国四大软件外包公司
  • 上海网站制作找缘魁南京seo网站优化推广
  • python网站建设代码嘉兴网站建设制作