day20 project+查看新聞列表 + 點贊 + 圖片驗證碼 + 評論和多級評論 + 後台管理 + webSocket + kindEditor

來源:互聯網
上載者:User

標籤:高度寬度   資料庫操作   create   ebs   .class   列表   資料庫   顯示   簡單   

Day20
回顧:
1. 請求生命週期

2. 中介軟體
  md = [
    "file_path.classname"
  ]
  process_request【可有可無】 process_response【必須有】
  process_request process_response
  process_request process_response
  process_request process_response
  process_request process_response

路由->函數
3. 路由系統
  a. /index/ -> func
  b. /index/(\d+) -> func()
  c. /prev/ -> include(‘xxx.urls‘)
  d. /detail/ -> func n1
  {% url n1 %}
  reverse(‘n1‘)
4. 視圖函數
  a. FBV
    def index(request):
    request.POST
    request.GET
    request.method
    request.FILES
    request.body
    request.COOKIE
    request.session
    request.path_info
    request...

    return render
    return redirect
    return HttpResponse

b. CBV
  class Foo(view):
    def dispatch
      pass

     def get

      ...
5. 模板引擎渲染
  a. Django後台完成渲染所有工作
  b. 字典,元組,列表: .
  c. simple_tag

6. 資料庫操作
  pymysql
    - 自己寫SQL語句
  ORM
    - 類和對象完成資料庫所有操作

    - 建立類
      - 單表
      - 一對一
      - 一對多
      - 多對多
      - 操作:
      ...

7. 分頁


8. Ajax提交
  $.ajax({
    url:
    type:
    data:
    dataType:
    headers:
    success:function(arg){


    }

  })


9. Django Form組件
  class:
    字典 = ()


  obj = Foo(reqest.GET)
  obj.is_valid()

10. 序列化



11. 其他:
  csrf
  緩衝
  訊號

今日內容:
1. project

  填充資料(admin):
    admin.py
      from repository import models

      admin.site.register(models.UserInfo)
      admin.site.register(models.Comment)
      admin.site.register(models.Favor)
      admin.site.register(models.News)
      admin.site.register(models.NewsType)
  建立使用者
    python manage.py createsuperuser
    root
    root!23456

   瀏覽器:
    http://127.0.0.1:8000/admin

  admin中顯示:
    class News(models.Model):
    nid = models.AutoField(primary_key=True)
    user_info = models.ForeignKey(‘UserInfo‘)
    class Meta:
    verbose_name_plural = ‘新聞‘ # 表名稱

    def __str__(self):
      return self.title # 行顯示內容
  驗證碼:
    1. pip3 install Pillow
    2. check_code.py 和 Monaco.ttf【項目跟目錄】
    3. <img src=‘/xxxxxx/‘>
    4.
    def xxxxx(request):
      img_obj, code = ac.create_validate_code()
      stream = BytesIO()
      img_obj.save(stream,‘png‘)
      request.session[‘check_code‘] = code
      return HttpResponse(stream.getvalue())

  2. 查看新聞列表
  3. 點贊
    後端:

    前端:
      position: relative; absolute;

      function ZMM(ths,txt) {
      var fontSize = 5;
      var left = 5;
      var top = 5;
      var opacity = 1;

      var tag = document.createElement(‘span‘);
      tag.innerHTML = txt;
      tag.style.position = "absolute";
      tag.style.fontSize = fontSize + ‘px‘;
      tag.style.left = left+ ‘px‘;
      tag.style.top = top+ ‘px‘;
      tag.style.opacity = opacity;
      $(ths).append(tag);

      var obj = setInterval(function () {
        fontSize = fontSize + 5;
        left = left + 5;
        top = top - 5;
        opacity = opacity - 0.1;
        tag.style.fontSize = fontSize + ‘px‘;
        tag.style.left = left+ ‘px‘;
        tag.style.top = top+ ‘px‘;
        tag.style.opacity = opacity;
        if(left > 60){
          clearInterval(obj);
          tag.remove();
        }
    },100);
    }

  4. 圖片驗證碼
  5. 評論和多級評論(**********)
    a. 結構化資料
    b. 遞迴產生HTML

  7. 後台管理
    - 簡單菜單(適用於固定個數菜單)
    - 動態菜單
    當前URL: /backend/host/

    a. 結構化資料
    b. 遞迴產生HTML


  6. WebSocket
    http://www.cnblogs.com/wupeiqi/p/6558766.html

  8. KindEditor[外掛程式] ---- 欠
    - 高度寬度
    - item
    -
      uploadJson: ‘/kind/upload_img/‘,
      extraFileUploadParams: {
      ‘csrfmiddlewaretoken‘: ‘{{ csrf_token }}‘
    },
    filePostName:‘fafafa‘


    def upload_img(request):
    """
     檔案上傳
    :param request:
    :return:
     """
    obj = request.FILES.get(‘fafafa‘)

    dic = {
    ‘error‘: 0,
    ‘url‘: ‘/static/imgs/20130809170025.png‘,
    ‘message‘: ‘錯誤了...‘
    }

    return HttpResponse(json.dumps(dic))


作業:整理今天

 

下周內容:
1. Alex,
   協同開發GitHub
   celery
   等

day20 project+查看新聞列表 + 點贊 + 圖片驗證碼 + 評論和多級評論 + 後台管理 + webSocket + kindEditor

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.