展示HTML網(wǎng)頁(yè)

1.導(dǎo)入正則模塊:re_path

2.settings配置靜態(tài)資源

STATICFILES_DIRS = [os.path.join(BASE_DIR,'static')]

3.settings 連接數(shù)據(jù)庫(kù)

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', #選擇MySQL數(shù)據(jù)庫(kù)
'NAME': 'test1', #數(shù)據(jù)庫(kù)名
'USER': 'root',
'PASSWORD': 'ryy123456',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}

4.views重定向
  • redirect重定向關(guān)鍵字
    from django.shortcuts import render,redirect from django.http import HttpResponse,HttpResponseRedirect
def hello(request):
   #響應(yīng)內(nèi)容
   #1.跟絕對(duì)路徑 2.跟相對(duì)路徑 3.HTTP
   #return redirect('http://127.0.0.1/index/')
   return  HttpResponseRedirect('/index/')

5.網(wǎng)頁(yè)添加標(biāo)題

def index(request):
   ctx = {'title':'首頁(yè)'}
    #重定向
   return render(request=request,template_name='index.html',context=ctx)
   type_list = models.Product.objects.values('type').distinct()   #distinct()去重
   name_list = models.Product.objects.values('name','type')

   title = '首頁(yè)'   
   #導(dǎo)入HTML文件 render  from django.shortcuts import render
   return render(request=request,template_name='index.html',context=locals())

6. init.py導(dǎo)入pymysql模塊

import pymysql
pymysql.install_as_MySQLdb()

7.遷移

1.生成遷移文件 2.執(zhí)行遷移

python manage.py makemigrations
python manage.py migrate

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 切換到創(chuàng)建項(xiàng)目的目錄 cd C:\Users\admin\Desktop\DjangoProject創(chuàng)建名為pr...
    在努力中閱讀 3,546評(píng)論 2 3
  • 模塊間聯(lián)系越多,其耦合性越強(qiáng),同時(shí)表明其獨(dú)立性越差( 降低耦合性,可以提高其獨(dú)立性)。軟件設(shè)計(jì)中通常用耦合度和內(nèi)聚...
    riverstation閱讀 2,233評(píng)論 0 8
  • 已經(jīng)同步到gitbook,想閱讀的請(qǐng)轉(zhuǎn)到gitbook: Django 1.10 中文文檔 This tutori...
    leyu閱讀 2,926評(píng)論 3 13
  • 22年12月更新:個(gè)人網(wǎng)站關(guān)停,如果仍舊對(duì)舊教程有興趣參考 Github 的markdown內(nèi)容[https://...
    tangyefei閱讀 35,438評(píng)論 22 257
  • 昨晚你打電話過來,話筒里傳來一片嘈雜,你告訴我你失戀了,我沒有聽清,然后你換了表達(dá)方式,你說你和她分手了。這一次我...
    譬如北晨閱讀 770評(píng)論 0 3

友情鏈接更多精彩內(nèi)容