亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
  • 通過排序來選擇最新的五篇文章

    top5_article_list?=?Article.objects.order_by('-article_id')[:5]
    paginator?=?Paginator(all_article,?3)
    page_num?=?paginator.num_pages
    page_article_list?=?paginator.page(page)
    if?page_article_list.has_next():
    ????next_page?=?page?+?1
    else:
    ????next_page?=?page
    if?page_article_list.has_previous():
    ????previous_page?=?page?-?1
    else:
    ????previous_page?=?page
    return?render(request,?'blog/index.html',?{
    ????'article_list':?page_article_list,
    ????'page_num':?range(1,?int(page_num)?+?1),
    ????'curr_page':?page,
    ????'previous_page':?previous_page,
    ????'next_page':?next_page,
    ????'top5_article_list':?top5_article_list
    })


    查看全部
  • 實現分頁按鈕

    設計?page= 的url

    def?get_index_page(request):
    ????page?=?request.GET.get('page')
    ????if?page:
    ????????page?=?int(page)
    ????else:
    ????????page?=?1
    ????all_article?=?Article.objects.all()
    ????paginator?=?Paginator(all_article,?3)
    ????page_num?=?paginator.num_pages
    ????page_article_list?=?paginator.page(page)
    ????if?page_article_list.has_next():
    ????????next_page?=?page?+?1
    ????else:
    ????????next_page?=?page
    ????if?page_article_list.has_previous():
    ????????previous_page?=?page?-?1
    ????else:
    ????????previous_page?=?page
    ????return?render(request,?'blog/index.html',?{
    ????????'article_list':?page_article_list,
    ????????'page_num':?range(1,?int(page_num)?+?1),
    ????????'curr_page':?page,
    ????????'previous_page':?previous_page,
    ????????'next_page':?next_page
    ????})


    查看全部
    0 采集 收起 來源:實現分頁功能

    2020-06-29

  • 在文章詳情頁增加前后篇文章的跳轉按鈕

    html改造

    def?get_detail_page(request,?article_id):
    ????curr_article?=?None
    ????previous_article?=?None
    ????next_article?=?None
    ????previous_index?=?0
    ????next_index?=?0
    ????all_article?=?Article.objects.all()
    ????for?index,?article?in?enumerate(all_article):
    ????????if?index?==?0:
    ????????????previous_index?=?0
    ????????????next_index?=?index?+?1
    ????????elif?index?==?len(all_article)?-?1:
    ????????????previous_index?=?index?-?1
    ????????????next_index?=?index
    ????????else:
    ????????????previous_index?=?index?-?1
    ????????????next_index?=?index?+?1
    ????????if?article.article_id?==?article_id:
    ????????????curr_article?=?article
    ????????????previous_article?=?all_article[previous_index]
    ????????????next_article?=?all_article[next_index]
    ????????????break
    ????return?render(request,?'blog/detail.html',?{
    ????????'curr_article':?curr_article,
    ????????'previous_article':?previous_article,
    ????????'next_article':?next_article
    ????})


    查看全部
  • 使用url來對指定文章的詳情頁進行訪問

    html加入a標簽

    是點擊可以跳轉鏈接

    查看全部
  • 使用模板系統實時的進行渲染

    將數據通過

    return?render(request,?'blog/detail.html',?{
    ????'curr_article':?curr_article
    })

    返回給頁面進行顯示

    查看全部
  • django的模板系統

    網頁邏輯和網頁視圖應該分開設計

    {{變量}}

    ?{%for x in list %},{% endfor %}

    ?{% if %},{% else %},?{% endif %}



    查看全部
  • 使用bootstrap實現靜態博客頁面

    簡單易上手

    柵格系統

    將頁面分為12份


    查看全部
  • 使用django的模板來渲染頁面

    進一步完成博客界面


    查看全部
    0 采集 收起 來源:章節導學

    2020-06-28

  • def?article_content(request):
    ????article?=?Article.objects.all()[0]
    ????title?=?article.title
    ????brief_content?=?article.brief_content
    ????content?=?article.content
    ????article_id?=?article.article_id
    ????publish_date?=?article.publish_date
    ????return_str?=?'title:%s,brief_content:%s,content:%s,article_id:%s,publish_date:%s'?%?(title,?brief_content,?content,
    ?????????????????????????????????????????????????????????????????????????????????????????article_id,?publish_date)
    ????return?HttpResponse(return_str)

    返回博客內容

    查看全部
  • django admin是自帶的后臺管理工具

    自己在admin中注冊模板

    from?.models?import?Article
    
    admin.site.register(Article)

    讓后臺管理顯示標題分辨不同文章

    def?__str__(self):
    ????return?self.title


    查看全部
  • django shell

    可以用于小范圍的debug

    python manage.py shell

    from blog.models import Article

    a=Article()

    a.title='Test shell'

    a.brief_content='hello shell'

    a.content='hello world hello django hello shell'

    a.save()

    print(Article.objects.all()[0].title)


    查看全部
    0 采集 收起 來源:初識 Django Shell

    2020-06-28

  • 博客包括

    標題

    摘要

    內容

    IntegerField

    TextField

    DateTimeField

    AutoField自增

    primary_key主鍵

    創建模型

    class?Article(models.Model):
    ????article_id=models.AutoField(primary_key=True)
    ????title=models.TextField()
    ????brief_content=models.TextField()
    ????content=models.TextField()
    ????publish_date=models.DateTimeField(auto_now=True)

    命令生成遷移文件

    python manage.py makemigrations

    命令導入文件

    python manage.py migrate

    查看全部
  • 視圖層與數據庫中間是模型層

    python與數據庫表之間轉換

    屏蔽數據庫之間的差異

    專注于業務邏輯的開發

    查看全部
    0 采集 收起 來源:模型層簡介

    2020-06-28

  • 模型層的定義

    如何創建一個文章的模型層

    了解django shell

    django admin模塊了解


    查看全部
    0 采集 收起 來源:章節導學

    2020-06-28

  • from?django.http?import?HttpResponse
    #?Create?your?views?here.
    def?hello_world(request):
    ????return?HttpResponse('hello?world')
    urlpatterns=[
    ????path('hello_world',blog.views.hello_world)
    ]

    完成項目路由,和應用路由對視圖函數的綁定

    查看全部
    0 采集 收起 來源:Django HelloWorld

    2020-06-28

舉報

0/150
提交
取消
課程須知
有簡單的Python語言基礎
老師告訴你能學到什么?
1. Django的項目結構 2. Django的應用開發 3. Django的路由配置 4. Django的視圖層 5. Django的模型層 6. Django的模板系統 7. Django的Admin模塊 8. Django的Shell

微信掃碼,參與3人拼團

微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

友情提示:

您好,此課程屬于遷移課程,您已購買該課程,無需重復購買,感謝您對慕課網的支持!