启动django 网页_使用Django模板

使用Django模板

1,

D:dj_examples>django-admin.py startproject muban

2

D:dj_examples>dir

3

2020/04/21 10:04 <DIR> muban

4

D:dj_examples>cd muban

5

dir

6

2020/04/21 10:04 646 manage.py

2020/04/21 10:04 <DIR> muban

7

D:dj_examplesmuban>cd muban

8

dir

9

2020/04/21 10:04 403 asgi.py

2020/04/21 10:04 3,205 settings.py

2020/04/21 10:04 768 urls.py

2020/04/21 10:04 403 wsgi.py

2020/04/21 10:04 0 __init__.py

10

cd..

11

D:dj_examplesmuban>manage.py runserver

12

D:dj_examplesmuban>manage.py runserver

Watching for file changes with StatReloader 监视文件的改变

Performing system checks... 系统检测

System check identified no issues (0 silenced).

You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.

你有17个没有应用的迁移,你的项目可能不会工作,直到你应用这些迁移。

管理,认证,内容类型,会话。

Run 'python manage.py migrate' to apply them.

运行 python manage.py migrate 来应用他们

April 21, 2020 - 10:07:25

Django version 3.0.5, using settings 'muban.settings'

日期,时间

Django版本是3.0.5

使用的配置是muban.settings

Starting development server at http://127.0.0.1:8000/

启动开发服务器,地址url是127.....

Quit the server with CTRL-BREAK.

退出服务器,ctrl break

_

光标闪烁

63c8c2a7a11893668277c96bdcb06bfc.png

[21/Apr/2020 10:13:56] "GET / HTTP/1.1" 200 16351

[21/Apr/2020 10:13:56] "GET /static/admin/css/fonts.css HTTP/1.1" 304 0

[21/Apr/2020 10:13:56] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 304 0

[21/Apr/2020 10:13:56] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 304 0

[21/Apr/2020 10:13:56] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 304 0

新建一个模板

在哪里新建?

D:dj_examplesmuban 的目录

2020/04/21 10:21 <DIR> .

2020/04/21 10:21 <DIR> ..

2020/04/21 10:07 0 db.sqlite3

2020/04/21 10:04 646 manage.py

2020/04/21 10:07 <DIR> muban

2020/04/21 10:22 <DIR> templates

D:dj_examplesmubantemplates 的目录

2020/04/21 10:22 <DIR> .

2020/04/21 10:22 <DIR> ..

2020/04/21 10:22 18 hello.html

hello.html的内容

<h1>{{hello}}</h1>

打开配置文件

TEMPLATES = [

{

'BACKEND': 'django.template.backends.django.DjangoTemplates',

'DIRS': [BASE_DIR+'/templates'], #修改路径

新建view.py

在哪里新建

D:dj_examplesmubanmuban 的目录

2020/04/21 10:30 <DIR> .

2020/04/21 10:30 <DIR> ..

2020/04/21 10:04 403 asgi.py

2020/04/21 10:26 3,240 settings.py

2020/04/21 10:04 768 urls.py

2020/04/21 10:29 160 view.py

from django.shortcuts import render
def hello(request):
    context={}
    context['hello']='hello world hi'
    return render(request,'hello.html',context)

修改urls.py

调用view.py

#在里面调用view.py定义的函数

from django.urls import path
from . import view

urlpatterns=[
    path('hello/',view.hello)#调用了hello
    ]

url里面调用了view

view里面传入了hello.html

settings指明了helo.html所在路径

render()根据

hello.html

查询到了hello变量

hello变量,根据context

查询到了内容

所以,hello.html里面存储的是字典的key

网页看到的内容是字典根据key查询返回的内容

启动服务器

D:dj_examplesmuban>manage.py runserver

总结:

fb2ab7687b859568bb9fab398d3e7257.png
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值