day57

当我们在浏览器输入一个地址,回车的时候发生了什么
 
DNS:记录着域名以及IP的对应关系 
 
 
 
 
 
1socket 
2路由(列表套元组),   根据uri的不同返回不同的页面结果.
3html和mysql结合,
    动态就是替换html里面的内容
 
 
 
urls.py
from django.conf.urls import url
from django.contrib import admin
#from django.shortcuts import render
 
 
from django.shortcuts import HttpResponse,render
 
 
def index(request):
   return render(request, "index.html",{'username':'ycl',
                                         'mylist':[1,2,"one"],
                                         "mydict":{'name':'ycl','age':18},
                                         "userinfo":[
                                             {'name':'qwe','age':18},
                                             {'name': 'zxc','age':19},
                                             {'name': 'asd', 'age': 20},
                                             {'name': 'plm', 'age': 21},
                                         ]
 
 
 
 
                                         }
                  )
 
 
 
 
def login(request):
    # get请求
    if request.method == 'GET':
        return render(request, "login.html")
    ##接收数据的时候是post请求
    else:
        username=request.POST.get('username')
        pwd=request.POST.get('pwd')
        #连数据库的方式查询
        if username == 'ycl' and pwd == '123':
            return HttpResponse('OK')
        else:
            return render(request, "login.html")
 
 
 
 
urlpatterns = [
    # url(r'^admin/', admin.site.urls),
    url(r'^index/', index),
    url(r'^login/',login),
]
 
 
login.html
 
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form action="/login/" method="post">
    用户名 : <input type="text" name="username">
 
    密码   : <input type="password" name="pwd">
 
    <input type="submit" value="登陆">
</form>
</body>
</html>
 
 
index.html
 
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/static/css/a.css">
</head>
<body>
<h1>my name is 007</h1>
<h2>{{ username }}</h2>
{{ mylist.0 }}
 
 
{#<ul>#}
{#  列表循环  #}
{#    {% for item in mylist %}#}
{#        <li>#}
{##}
{#            {{ item }}#}
{##}
{#        </li>#}
{#    {% endfor %}#}
{#</ul>#}
{#字典循环#}
<hr>
{#<ul>#}
{#    {% for key,val in mydict.items %}#}
{#        <li>#}
{#            {{ key }} : {{ val }}#}
{#        </li>#}
{#    {% endfor %}#}
{#</ul>#}
{#列表套字典变成表单#}
{#<table border="1px">#}
{#    <thead>#}
{#        <tr>#}
{#            <th>name</th>#}
{#            <th>age</th>#}
{#        </tr>#}
{#    </thead>#}
{#    <tbody>#}
{#        {% for user in userinfo %}#}
{#            <tr>#}
{#                <td>{{ user.name }}</td>#}
{#                <td>{{ user.age }}</td>#}
{#            </tr>#}
{#        {% endfor %}#}
{#    </tbody>#}
{#</table>#}
 
 
</body>
</html>
posted @ 2019-07-09 22:42  轩辕12  阅读(99)  评论(0编辑  收藏  举报