Django零基礎(chǔ)入門之調(diào)用漂亮的HTML前端頁面
引言:
Django如何調(diào)用HTML前端頁面呢?
Django怎樣去調(diào)用漂亮的HTML前端頁面呢?
就直接使用render方法即可!
render方法是django封裝好用來調(diào)用HTML前端模板的方法!
1.模板放在哪?
在主目錄下創(chuàng)建一個templates目錄用來存放所有的html的模板文件。(如果是使用pycharm創(chuàng)建django項目的話,默認(rèn)就會自動創(chuàng)建這個目錄哦!但是用命令創(chuàng)建django項目的話是沒有此目錄的?。?/p>
templates目錄里面再新建各個以app名字命名的目錄來存放各個app中的模板文件。
2.Django中實戰(zhàn)使用——調(diào)用漂亮的HTML前端頁面
(1)App music里面的views.py文件:
from django.shortcuts import render,redirect,reverse from django.http import HttpResponse import time # Create your views here. def login(request): #登陸 return render(request,"music/test01.html") #返回HTML模板 #第二個html文件的路徑可以直接寫templates下的:因為在settings.py文件中已經(jīng)配置好了!
注意:如果是使用pycharm創(chuàng)建的django項目,templates目錄路徑是已經(jīng)添加到DIRS中了哦!
如果是使用命令創(chuàng)建的Django項目,需要你自行添加此值哦!
(2)App music里面的views.py文件:
from django.contrib import admin from django.urls import path from . import views urlpatterns = [ #子路由 path("login/",views.login), ]
(3)HTML模板文件:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>注冊界面</title> <link rel="stylesheet" href="RESETCSS.css" rel="external nofollow" > <style> div{ width: 300px; height: 350px; border: 1px solid grey; margin: 8px 0 0 8px; } span{ border-bottom: 3px solid purple; padding-bottom: 3px; } a{ text-decoration: none; float: right; padding-top: 3px; color: deepskyblue; } .first{ width: 290px; height: 30px; border: 1px solid grey; border-radius: 5px; margin: 5px 4px; } .second{ width: 200px; height: 30px; border: 1px solid grey; border-radius: 5px; margin: 5px 4px; } .third{ width: 79px; height: 30px; border: 1px solid blue; border-radius: 5px; color: blue; } .fourth{ width: 79px; height: 30px; border: 1px solid blue; border-radius: 5px; vertical-align: middle; background-image: url("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1378353400,959510337&fm=26&gp=0.jpg"); background-size: 79px 30px; } .zc{ width: 290px; height: 30px; border: 1px solid grey; border-radius: 5px; margin: 5px 4px; background-color: skyblue; color: white; } </style> </head> <body> <div> <form action=""> <span>請注冊</span> <a href="">立即登錄<</a> <hr> <input type="text" class="first" placeholder="請輸入手機號"><br> <input type="text" class="second" placeholder="請輸入短信驗證碼"> <input type="button" class="third" value="發(fā)送驗證碼"><br> <input type="text" class="first" placeholder="請輸入用戶名"><br> <input type="password" class="first" placeholder="請輸入密碼"><br> <input type="password" class="first" placeholder="請再次輸入密碼"><br> <input type="text" class="second" placeholder="請輸入圖形驗證碼"> <input type="button" class="fourth"><br> <input type="submit" class="zc" value="立即注冊"><br> </form> </div> </body> </html>
(4)實現(xiàn)效果:
到此這篇關(guān)于Django零基礎(chǔ)入門之調(diào)用漂亮的HTML前端頁面的文章就介紹到這了,更多相關(guān)Django調(diào)用HTML頁面內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Pytorch自定義CNN網(wǎng)絡(luò)實現(xiàn)貓狗分類詳解過程
PyTorch是一個開源的Python機器學(xué)習(xí)庫,基于Torch,用于自然語言處理等應(yīng)用程序。它不僅能夠?qū)崿F(xiàn)強大的GPU加速,同時還支持動態(tài)神經(jīng)網(wǎng)絡(luò)。本文將介紹PyTorch自定義CNN網(wǎng)絡(luò)實現(xiàn)貓狗分類,感興趣的可以學(xué)習(xí)一下2022-12-12Python通過RabbitMQ服務(wù)器實現(xiàn)交換機功能的實例教程
RabbitMQ是一個基于消息隊列的服務(wù)器程序,Python可以通過Pika庫來驅(qū)動它,這里我們將來看一個Python通過RabbitMQ服務(wù)器實現(xiàn)交換機功能的實例教程:2016-06-06在Python中畫圖(基于Jupyter notebook的魔法函數(shù))
這篇文章主要介紹了在Python中畫圖(基于Jupyter notebook的魔法函數(shù)),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2019-10-10python通過函數(shù)名調(diào)用函數(shù)的幾種方法總結(jié)
今天帶大家學(xué)習(xí)的是怎么使用python通過函數(shù)名調(diào)用函數(shù),文中對python通過函數(shù)名調(diào)用函數(shù)的幾種方法有非常詳細(xì)的介紹,需要的朋友可以參考下2021-06-06跟老齊學(xué)Python之關(guān)于循環(huán)的小伎倆
不管是while還是for,所發(fā)起的循環(huán),在python編程中是經(jīng)常被用到的。特別是for,一般認(rèn)為,它要比while快,而且也容易寫(是否容易,可能因人而異,但是,執(zhí)行時間快,是的確的),因此在實踐中,for用的比較多點。2014-10-10解決TensorFlow調(diào)用Keras庫函數(shù)存在的問題
這篇文章主要介紹了解決TensorFlow調(diào)用Keras庫函數(shù)存在的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07python神經(jīng)網(wǎng)絡(luò)學(xué)習(xí)利用PyTorch進行回歸運算
這篇文章主要為大家介紹了python神經(jīng)網(wǎng)絡(luò)學(xué)習(xí)利用PyTorch進行回歸運算的實現(xiàn)代碼,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-05-05