最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

用pycharm開發(fā)django項(xiàng)目示例代碼

 更新時(shí)間:2018年10月24日 08:32:47   作者:kylinlin  
這篇文章主要介紹了用pycharm開發(fā)django項(xiàng)目示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

在pycharm(企業(yè)版)中新建Django工程,注意使用虛擬環(huán)境

創(chuàng)建成功后,在pycharm顯示的工程目錄結(jié)構(gòu)如下:

打開pycharm的Terminal,進(jìn)入該工程的目錄新建一個(gè)django工程

python3 manage.py startapp django_web

執(zhí)行成功后,工程目錄結(jié)構(gòu)如下:

修改settings.py文件,注冊(cè)該工程

Django的開發(fā)遵循MTV模式(models, templates, views),views.py負(fù)責(zé)執(zhí)行操作,models.py負(fù)責(zé)數(shù)據(jù)處理(如數(shù)據(jù)庫(kù)連接),templates目錄下存放網(wǎng)頁(yè)的模板

首先在templates下新建一個(gè)index.html文件,并把以下內(nèi)容替換到該文件中

<!DOCTYPE html>

<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>The blah</title>
  <link rel="stylesheet" type="text/css" href=" new_blah.css">
</head>
<body>

<div class="header">
  <img src="images/blah.png">
  <ul class="nav">
    <li><a href="#">Home</a></li>
    <li><a href="#">Site</a></li>
    <li><a href="#">Other</a></li>
  </ul>

</div>

<div class="main-content">
  <h2>Article</h2>
  <ul class="article">

    <li>
      <img src="images/0001.jpg" width="100" height="90">
      <h3><a href="#">The blah</a></h3>
      <p>This is a dangerously delicious cake.</p>
    </li>

    <li>
      <img src="images/0002.jpg" width="100" height="90">
      <h3><a href="#">The blah</a></h3>
      <p>It's always taco night somewhere!</p>
    </li>

    <li>
      <img src="images/0003.jpg" width="100" height="90">
      <h3><a href="#">The blah</a></h3>
      <p>Omelette you in on a little secret </p>
    </li>

    <li>
      <img src="images/0004.jpg" width="100" height="90">
      <h3><a href="#">The blah</a></h3>
      <p>It's a sandwich. That's all we .</p>
    </li>
  </ul>
</div>

<div class="footer">
  <p>&copy; Mugglecoding</p>
</div>
</body>
</html>

<--!http://css3gen.com/box-shadow/-->

首先編寫views.py文件,定義訪問(wèn)這個(gè)index.html文件的操作

def index(request): 

   return render(request, 'index.html')

編寫urls.py文件,定義訪問(wèn)這個(gè)index.html的url路徑(使用正則表達(dá)式)

from django.conf.urls import url 
from django.contrib import admin 
from django_web.views import index #導(dǎo)入views.py文件中的index函數(shù) 

urlpatterns = [ 
  url(r'^admin/', admin.site.urls), 
  url(r'^index/', index), #在url中凡是以u(píng)rl開頭的訪問(wèn)都使用index函數(shù)來(lái)處理該請(qǐng)求 
]

在pycharm的Terminal中輸入命令運(yùn)行服務(wù)器:

python3 manager.py runserver

在瀏覽器中輸入url:http://127.0.0.1:8000/index/ 可以看到如下的格式,接下來(lái)要做的就是添加資源

將css文件(css文件的內(nèi)容在最后)和圖片(隨意找?guī)讖垐D片,更名為如下所示即可)都復(fù)制到env5工程下的一個(gè)名為static的文件,工程結(jié)構(gòu)如下:

 注意:一定要保證與templates目錄同級(jí)

修改index.html如下

{% load static %}

<html>

<head>
  <link rel="stylesheet" type="text/css" href="{% static 'css/new_blah.css' %}">
</head>
<body>

<div class="header">
  <img src="{% static 'images/blah.png' %}">
  <ul class="nav">
    <li><a href="#">Home</a></li>
    <li><a href="#">Site</a></li>
    <li><a href="#">Other</a></li>
  </ul>
</div>

<div class="main-content">
  <h2>Article</h2>
  <ul class="articles">

    <li>
      <img src="{% static 'images/0001.jpg' %}" width="100" height="91">

      <div class="article-info">
        <h3><a href="#">The blah</a></h3>
        <p class="meta-info">
          <span class="meta-cate">fun</span>
          <span class="meta-cate">Wow</span>
        </p>
        <p class="description">Just say something.</p>
      </div>

      <div class="rate">
        <span class="rate-score">4.5</span>
      </div>
    </li>

    <li>
      <img src="{% static 'images/0002.jpg' %}" width="100" height="91">
      <div class="article-info">
        <h3><a href="#">The blah</a></h3>
        <p class="meta-info">
          <span class="meta-cate">butt</span>
          <span class="meta-cate">NSFW</span>
        </p>
        <p class="description">Just say something.</p>
      </div>

      <div class="rate">
        <img src="{% static 'images/Fire.png' %}" width="18" height="18">
        <span class="rate-score">5.0</span>
      </div>
    </li>

    <li>
      <img src="{% static 'images/0003.jpg' %}" width="100" height="91">
      <div class="article-info">
        <h3><a href="#">The blah</a></h3>
        <p class="meta-info">
          <span class="meta-cate">sea</span>
        </p>
        <p class="description">Just say something.</p>
      </div>

      <div class="rate">
        <span class="rate-score">3.5</span>
      </div>
    </li>

    <li>
      <img src="{% static 'images/0004.jpg' %}" width="100" height="91">
      <div class="article-info">
        <h3><a href="#">The blah</a></h3>
        <p class="meta-info">
          <span class="meta-cate">bay</span>
          <span class="meta-cate">boat</span>
          <span class="meta-cate">beach</span>
        </p>
        <p class="description">Just say something.</p>
      </div>

      <div class="rate">
        <span class="rate-score">3.0</span>
      </div>
    </li>
  </ul>
</div>

<div class="footer">
  <p>&copy; Mugglecoding</p>
</div>
</body>

</html>

在settings.py文件的最后增加如下配置

STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),)

再次打開瀏覽器就可以看到正常的顯示

css文件

body {
  padding: 0 0 0 0;
  background-color: #ffffff;
  background-image: url(../images/bg3-dark.jpg);
  background-position: top left;
  background-repeat: no-repeat;
  background-size: cover;
  font-family: Helvetica, Arial, sans-serif;
}


.main-content {
  width: 500px;
  padding: 20px 20px 20px 20px;
  border: 1px solid #dddddd;
  border-radius:15px;
  margin: 30px auto 0 auto;
  background: #fdffff;
  -webkit-box-shadow: 0 0 22px 0 rgba(50, 50, 50, 1);
  -moz-box-shadow:  0 0 22px 0 rgba(50, 50, 50, 1);
  box-shadow:     0 0 22px 0 rgba(50, 50, 50, 1);


}
.main-content p {
  line-height: 26px;
}
.main-content h2 {
  color: #585858;
}
.articles {
  list-style-type: none;
  padding: 0;
}
.articles img {
  float: left;
  padding-right: 11px;
}
.articles li {
  border-top: 1px solid #F1F1F1;
  background-color: #ffffff;
  height: 90px;
  clear: both;
}
.articles h3 {
  margin: 0;
}
.articles a {
  color:#585858;
  text-decoration: none;
}
.articles p {
  margin: 0;
}

.article-info {
  float: left;
  display: inline-block;
  margin: 8px 0 8px 0;
}

.rate {
  float: right;
  display: inline-block;
  margin:35px 20px 35px 20px;
}

.rate-score {
  font-size: 18px;
  font-weight: bold;
  color: #585858;
}

.rate-score-hot {


}

.meta-info {
}

.meta-cate {
  margin: 0 0.1em;
  padding: 0.1em 0.7em;
  color: #fff;
  background: #37a5f0;
  font-size: 20%;
  border-radius: 10px ;
}

.description {
  color: #cccccc;
}

.nav {
  padding-left: 0;
  margin: 5px 0 20px 0;
  text-align: center;
}
.nav li {
  display: inline;
  padding-right: 10px;
}
.nav li:last-child {
  padding-right: 0;
}
.header {
  padding: 10px 10px 10px 10px;

}

.header a {
  color: #ffffff;
}
.header img {
  display: block;
  margin: 0 auto 0 auto;
}
.header h1 {
  text-align: center;
}



.footer {
  margin-top: 20px;
}
.footer p {
  color: #aaaaaa;
  text-align: center;
  font-weight: bold;
  font-size: 12px;
  font-style: italic;
  text-transform: uppercase;
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • python針對(duì)excel的操作技巧

    python針對(duì)excel的操作技巧

    這篇文章主要介紹了python針對(duì)excel的操作方法,需要的朋友可以參考下
    2018-03-03
  • 解決Python pandas df 寫入excel 出現(xiàn)的問(wèn)題

    解決Python pandas df 寫入excel 出現(xiàn)的問(wèn)題

    今天小編就為大家分享一篇解決Python pandas df 寫入excel 出現(xiàn)的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-07-07
  • Python利用pyecharts實(shí)現(xiàn)數(shù)據(jù)可視化的示例代碼

    Python利用pyecharts實(shí)現(xiàn)數(shù)據(jù)可視化的示例代碼

    Pyecharts是一個(gè)用于生成 Echarts 圖表的 Python 庫(kù),Echarts 是一個(gè)由百度開源的數(shù)據(jù)可視化工具,它提供的圖表種類豐富,交互性強(qiáng),兼容性好,非常適合用于數(shù)據(jù)分析結(jié)果的展示,本文將給大家介紹Python利用pyecharts實(shí)現(xiàn)數(shù)據(jù)可視化,需要的朋友可以參考下
    2024-09-09
  • pytorch查看通道數(shù) 維數(shù) 尺寸大小方式

    pytorch查看通道數(shù) 維數(shù) 尺寸大小方式

    這篇文章主要介紹了pytorch查看通道數(shù) 維數(shù) 尺寸大小方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-05-05
  • Python Numpy 控制臺(tái)完全輸出ndarray的實(shí)現(xiàn)

    Python Numpy 控制臺(tái)完全輸出ndarray的實(shí)現(xiàn)

    這篇文章主要介紹了Python Numpy 控制臺(tái)完全輸出ndarray的實(shí)現(xiàn)方式,希望給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧
    2020-02-02
  • 使用python編寫監(jiān)聽端

    使用python編寫監(jiān)聽端

    這篇文章主要為大家詳細(xì)介紹了使用python編寫監(jiān)聽端,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • Python?命令行?prompt_toolkit?庫(kù)詳解

    Python?命令行?prompt_toolkit?庫(kù)詳解

    prompt_toolkit 是一個(gè)用于構(gòu)建強(qiáng)大交互式命令行的 Python 工具庫(kù)。接下來(lái)通過(guò)本文給大家介紹Python?命令行?prompt_toolkit?庫(kù)的相關(guān)知識(shí),感興趣的朋友一起看看吧
    2022-01-01
  • 如何用python抓取B站數(shù)據(jù)

    如何用python抓取B站數(shù)據(jù)

    今天介紹一個(gè)獲取B站數(shù)據(jù)的Python擴(kuò)展庫(kù)-bilibili_api,對(duì)此感興趣的同學(xué),可以實(shí)驗(yàn)一下
    2021-05-05
  • Python中sklearn實(shí)現(xiàn)交叉驗(yàn)證示例分析

    Python中sklearn實(shí)現(xiàn)交叉驗(yàn)證示例分析

    這篇文章主要介紹了Python中sklearn實(shí)現(xiàn)交叉驗(yàn)證,本文python的版本為3.8,各個(gè)版本之間函數(shù)名字略有不同,但是原理都是一樣的,集成開發(fā)環(huán)境使用的是Anaconda的Spyder,需要的朋友可以參考下
    2023-08-08
  • 使用Pytorch如何完成多分類問(wèn)題

    使用Pytorch如何完成多分類問(wèn)題

    這篇文章主要介紹了使用Pytorch如何完成多分類問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-02-02

最新評(píng)論

铁岭县| 玉屏| 蓬安县| 遵化市| 蛟河市| 资溪县| 宾川县| 灵台县| 普安县| 常宁市| 新蔡县| 长岛县| 根河市| 江达县| 罗平县| 巴南区| 通许县| 张北县| 阳春市| 余江县| 通化市| 县级市| 即墨市| 开鲁县| 宁乡县| 东阳市| 石河子市| 苗栗县| 浦北县| 怀安县| 邵阳县| 阿勒泰市| 天等县| 正宁县| 阜新市| 十堰市| 怀安县| 靖宇县| 亳州市| 勐海县| 本溪|