• Django 初识


    1、web框架的本质

      浏览器和 scoket服务端通信

    2、scoket服务端功能划分

      a、负责与浏览器进行通信

      b、根据访问不同的url执行不同的函数

      c、从HTML文件中读取内容

    3、Python中web框架的划分

      a、按照功能划分

        1、框架自带a,b,c  Tornado

         2、框架自带b,c 使用第三方a  Django

         3、框架自带b,使用第三方的a和c  Flash

      b、按照其它划分

        1、Django  大而全

        2、other  轻量级

    4、请求和响应

      a、请求(resquest)

        浏览器->socket服务端

      b、响应(response)

        socket服务器->浏览器

    5、url与函数的对应关系(urls.py)

    # 存放url与函数的对应关系
    urlpatterns = [
        path('url/', 函数名),
    ]

    6、函数(urls.py)

    from django.shortcuts import HttpResponse
    # request参数保存所有和用户浏览器相关的请求数据
    def test(request):
        return HttpResponse("Hello World")

    7、提交HTML页面(urls.py)

    from django.shortcuts import render
    def test(request):
        return render(request, "test.html")

    8、设置静态文件的路径(setting.py)

    # 存放静态文件(CSS JavaScript Images)
    STATICFILES_DIRS = [
        os.path.join(BASE_DIR, "static")
    ]

    使用路径

    /static/bootstrap/css/bootstrap.min.css

      

  • 相关阅读:
    bzoj violet系列 (2708~2725)
    bzoj4692: Beautiful Spacing
    896.Montonic Array
    56. Merge Intervals
    767. Reorganize String
    872. Leaf-Similar Trees
    使用Spring MVC开发RESTful API(续)
    690. Employee Importance
    429. N-ary Tree Level Order Traversal
    使用Spring MVC开发RESTful API
  • 原文地址:https://www.cnblogs.com/wt7018/p/11219644.html
Copyright © 2020-2023  润新知