The front end of a preliminary study

The nature of web services

Software development framework

c/s

b/s

Enter typing the URL in the browser sends a few things?

1. The browser sends the request towards the service side

2. The server receives the request

3. The server returns a corresponding response

4. The browser receives the response, rendering the page display to the user according to specific rules to see

 

 

What is the front-end

The front has nothing to do with Python, any deal directly with the user interface can be called front-end

ps: the computer screen, mobile phone interface, tablet interface

HTTP protocol

Hypertext Transfer Protocol

It specifies the format of the message data transmitted between the browser and the server

  Four features

  1. Based on the request response

  2. Based on the role of a TCP / IP protocol in the application layer

  3. No state (the server can not save the user's status, a person to a thousand times, I do not remember, but also when you are as shown signs)

  4. No connection (primary response request once, immediately after disconnect, there is no longer any relationship between the two)

  websocket the equivalent of a large patch of the HTTP protocol that supports long connection

 

  Request data format

  The first line of the request (HTTP protocol version identifies the current request method)

  Request header (lot k, v key-value pairs)

   Request body (carrying some sensitive information such as: passwords, social security number)

  

  Response data format

  The first line of response (HTTP protocol version identifier, the response status code)

  Response header (lot k, v key-value pairs)

  Response body (the data back to the browser page, usually the response body are HTML pages)

 

  The response status code

  By a string of simple numbers to represent some complex state or message

  1XX: the server has successfully received your data is being processed, you can continue to submit additional data

  2XX: a successful response data server you want (the request was successful 200)

  3XX: Redirection (when the page you can access after a visit need to be logged, you will find that the window will be automatically transferred to the login page 301 302)

  4XX: request error (there is no resource request 404, the request does not meet the legal and internal regulations enough authority 403)

  5XX: internal server error (500)

  

  Request method

  1.get request: To end toward the service resource (such as a browser window, enter the URL (www.baidu.com))

  2.post request: Submit data towards the server (such as user login, submit your username and password)

  URL: Uniform Resource Locator (URL is vernacular)

 

 

 

HTML

Hypertext Markup Language

HTML是一种标记语言(markup language),它不是一种编程语言。

HTML使用标签来描述网页。

要想让你的页面能够正常被浏览器显示出来,你所写的页面就必须遵循HTML标记语法也就意味着所有能够被浏览器显示出来的页面,内部都是HTML代码

浏览器只认识HTML,CSS,JS(JavaScript)

每一个标签都应该有三个比较重要的属性

  id:定义标签的唯一ID,HTML文档树中唯一

  class:为html元素定义一个或多个类名(classname)(CSS样式类名)

  style:规定元素的行内样式(CSS样式)

 

1.<!DOCTYPE html>声明为HTML5文档。

2.<html>、</html>是文档的开始标记和结束的标记。是HTML页面的根元素,在它们之间是文档的头部(head)和主体(body)。

3.<head>、</head>定义了HTML文档的开头部分。它们之间的内容不会在浏览器的文档窗口显示。包含了文档的元(meta)数据。

4.<title>、</title>定义了网页标题,在浏览器标题栏显示。

5.<body>、</body>之间的文本是可见的网页主体内容。

注意:对于中文网页需要使用 <meta charset="utf-8"> 声明编码,否则会出现乱码。有些浏览器会设置 GBK 为默认编码,则你需要设置为 <meta charset="gbk">。

 

 

HTML注释 写网页的一套标准

注释是代码之母
    <!--单行注释-->
    <!--
    多行注释
    多行注释
    -->
一般情况下 html的注释都会按照下面的方式书写
<!--导航条样式开始-->

<!--导航条样式结束-->

HTML文档结构
    <html>
    <head></head>:head内的标签 不是用来展示给用户看的  而是定义一些配置 主要是给浏览器看的
    <body></body>:body内的标签 就是浏览器展示给用户看的内容
    </html>

 

 

 

 

打开html页面的两种方式
1.找到文件路径 选择浏览器打开
2.pycharm快捷方式直接打开

 

 

标签的分类1:
1.双标签(<h1></h1> <a></a>)
2.单标签(自闭和标签 <img/>)

 

 

head内常用标签

title用来显示网页标题
style用来控制样式的 内部支持写css代码
script内部支持写js代码 也支持导入外界的js文件
link专门用来引入外部的css文件

 

 

标签的分类2
1.块儿级标签(独占浏览器一行)
div p h
1.块儿级标签可以修改长宽
2.块儿级标签内部可以嵌套任意的块级标签
但是p标签虽然是块儿级标签 但是他不能够其他块儿级标签 包括自身
可以嵌套行内标签
总结:
只要是块儿级标签 都可以嵌套行内标签
p标签只能嵌套行内 其他块儿级可以嵌套任意的块儿级标签
2.行内标签(自身文本多大就占多大)
span b s i u

div和span通常都是用来构建网页布局的

 

 

 

body内常用标签
基本标签
  h标签:标题标签
  p标签:段落标签

<b>加粗</b>
<i>斜体</i>
<u>下划线</u>
<s>删除</s>

<p>段落标签</p>

<h1>标题1</h1>
<h2>标题2</h2>
<h3>标题3</h3>
<h4>标题4</h4>
<h5>标题5</h5>
<h6>标题6</h6>

<!--换行-->
<br>

<!--水平线--><hr>

 



符号

常用标签
  div
  span
  p

img标签
    

<img src="图片的路径" alt="图片未加载成功时的提示" title="鼠标悬浮时提示信息" 
width
="宽" height="高(宽高两个属性只用一个会自动等比缩放)">

 

 

 

 

a标签

超链接标签

所谓的超链接是指从一个网页指向一个目标的连接关系,这个目标可以是另一个网页,也可以是相同网页上的不同位置,还可以是一个图片,一个电子邮件地址,一个文件,甚至是一个应用程序。

href后面存放url的时候 点击跳转到该url
如果该链接没有被点过 那么默认是蓝色,只要点过依次 之后都是紫色

target 默认是_self当前页面跳转
_blank新建页面跳转

锚点功能(回到顶部)
href还可以写另一个a标签的id值,点击就会跳到id值所对应的a标签

 

<a href="http://www.oldboyedu.com" target="_blank" >点我</a>

 

 

 

 

每一个标签都应该有三个比较重要的属性
  1.id值 该值就类似于人的身份证号 在用一个html文档id应该保证唯一不重复
  2.class值 该值就类似于面向对象里面的继承 可以写多个
  3.style(不是必备) 支持在标签内直接写css代码 属于行内样式 优先级最高
  补充 任何标签都支持自定义属性!!!

 

列表

1.无序列表

 

<ul type="disc">
  <li>第一项</li>
  <li>第二项</li>
</ul>

 

type属性:

  • disc(实心圆点,默认值)
  • circle(空心圆圈)
  • square(实心方块)
  • none(无样式)

 

 

2.有序列表

 

<ol type="1" start="2">
  <li>第一项</li>
  <li>第二项</li>
</ol>

 

type属性:

  • 1 数字列表,默认值
  • A 大写字母
  • a 小写字母
  • Ⅰ大写罗马
  • ⅰ小写罗马

 

3.标题列表

<dl>
  <dt>标题1</dt>
  <dd>内容1</dd>
  <dt>标题2</dt>
  <dd>内容1</dd>
  <dd>内容2</dd>
</dl>

 

 

表格

表格是一个二维数据空间,一个表格由若干行组成,一个行又有若干单元格组成,单元格里可以包含文字、列表、图案、表单、数字符号、预置文本和其它的表格等内容。
表格最重要的目的是显示表格类数据。表格类数据是指最适合组织为表格格式(即按行和列组织)的数据。
表格的基本结构:

<table>
  <thead>
  <tr>
    <th>序号</th>
    <th>姓名</th>
    <th>爱好</th>
  </tr>
  </thead>
  <tbody>
  <tr>
    <td>1</td>
    <td>yyy</td>
    <td>333</td>
  </tr>
  <tr>
    <td>2</td>
    <td>jjj</td>
    <td>日天</td>
  </tr>
  </tbody>
</table>

 


        tr表示一行
        th和td都是文本
            建议在thead内用th
            tbody内用td
        
        colspan表示的水平方向
        rowspan表示的竖直方向
        
    

 属性:

  • border: 表格边框.
  • cellpadding: 内边距
  • cellspacing: 外边距.
  • width: 像素 百分比.(最好通过css来设置长宽)
  • rowspan: 单元格竖跨多少行
  • colspan: 单元格横跨多少列(即合并单元格)

 

 

form

功能:

表单用于向服务器传输数据,从而实现用户与Web服务器的交互

表单能够包含input系列标签,比如文本字段、复选框、单选框、提交按钮等等。

表单还可以包含textarea、select、fieldset和 label标签。

表单属性:

 

 

 

表单元素

基本概念:
HTML表单是HTML元素中较为复杂的部分,表单往往和脚本、动态页面、数据处理等功能相结合,因此它是制作动态网站很重要的内容。
表单一般用来收集用户的输入信息
表单工作原理:
访问者在浏览有表单的网页时,可填写必需的信息,然后按某个按钮提交。这些信息通过Internet传送到服务器上。 
服务器上专门的程序对这些数据进行处理,如果有错误会返回错误信息,并要求纠正错误。当数据完整无误后,服务器反馈一个输入完成的信息。

from django.conf.urls import url
from django.shortcuts import HttpResponse


def upload(request):
    print("request.GET:", request.GET)
    print("request.POST:", request.POST)

    if request.FILES:
        filename = request.FILES["file"].name
        with open(filename, 'wb') as f:
            for chunk in request.FILES['file'].chunks():
                f.write(chunk)
            return HttpResponse('上传成功')
    return HttpResponse("收到了!")

urlpatterns = [
    url(r'^upload/', upload),
]

Django接收上传文件代码

 

input

<input> 元素会根据不同的 type 属性,变化为多种形态。

属性说明:

  • name:表单提交时的“键”,注意和id的区别
  • value:表单提交时对应项的值checked:radio和checkbox默认被选中的项
    • type="button", "reset", "submit"时,为按钮上显示的文本年内容
    • type="text","password","hidden"时,为输入框的初始值
    • type="checkbox", "radio", "file",为输入相关联的值
  • readonly:text和password设置只读
  • disabled:所有input均适用

 

 

form表单默认是get请求 你需要通过method参数 换成post提交
    form表单中 要想触发提交动作 
        只有两种情况可以
            1.input标签type指定成submit
            2.直接写button标签
        
        获取用户输入(输入 选择 上传...)的标签 都必须有一个name属性
        这个name属性就类似于字典的key,而标签获取到的用户写入的值就类似于字典的value
<input type="text" id="d1" name="username" value="默认值">
        name就相当于是字典的key
        value就是字典的值
        获取都的用户输入都会被放入value属性中
    form表单传文件的时候 需要指定enctype参数
emmet插件
防呆措施

 

select标签

<form action="" method="post">
  <select name="city" id="city">
    <option value="1">北京</option>
    <option selected="selected" value="2">上海</option>
    <option value="3">广州</option>
    <option value="4">深圳</option>
  </select>
</form>

属性说明:

  • multiple:布尔属性,设置后为多选,否则默认单选
  • disabled:禁用
  • selected:默认选中该项
  • value:定义提交时的选项值

 

label标签

定义:<label> 标签为 input 元素定义标注(标记)。
说明:

    1. label 元素不会向用户呈现任何特殊效果。
    2. <label> 标签的 for 属性值应当与相关元素的 id 属性值相同。
<form action="">
  <label for="username">用户名</label>
  <input type="text" id="username" name="username">
</form>

 

 

textarea多行文本

<textarea name="memo" id="memo" cols="30" rows="10">
  默认内容
</textarea>

属性说明:

  • name:名称
  • rows:行数
  • cols:列数
  • disabled:禁用

Guess you like

Origin www.cnblogs.com/AbrahamChen/p/11454972.html