Django - 内容总结(1)

内容整理:

1、创建django工程名称

  django-admin startproject 工程名

2、创建app

  cd 工程名

  python manage.py startapp cmdb

3、静态文件

  settings.py 

  增加STATICFILES_DIRS=(os.path.join(BASE_DIR,static),)

4、模板文件

  DIRS=>[os.path.join(BASE_DIR,"templates"),]

5、settings.py中

  middleware中

  注释csrf

6、定义路由规则

  url.py

  'login.py' - >函数名

7、定义视图函数

  app下的views.py

  def func(request):
    pass

    #request.method    GET/POST(大写)

    #request.POST.get('',none)

    #request.GET.get('',none)

    #url = 127.0.0.1:8000/home?nid=123&name=alex

    request.GET.get('nid') 即可获取url中的nid的值。

 8、模板渲染

  特殊的模板语言

  def func(request):
    return render(request,"home.html",{"current_user":"alex"})

    #字典参数,做为html中参数传入。

    for循环:

      {% for row in user_list%}

      {%endfor%}

    user_list.0(列表)

    user_list.key1(字典)

         if 判断:

     {%if %}

     {%endif%}

猜你喜欢

转载自www.cnblogs.com/wulafuer/p/9289860.html
今日推荐