美文网首页django
django:使用模板的简单例子

django:使用模板的简单例子

作者: dddddo | 来源:发表于2019-11-15 08:00 被阅读0次

创建django项目projectaa,创建应用appaa。
在urls窗口编写代码,projectaa/projectaa/urls:

from django.contrib import admin
from django.urls import path
from appaa import views
urlpatterns = [
    path('admin/', admin.site.urls),
    path('aa/', views.aa),
]

在views窗口编写代码,projectaa/appaa/views:

from django.shortcuts import HttpResponse, render
def bb(request):
    return render(request, 'aaaa.html')

在template创建aaaa.html,并编写代码,projectaa/template/aaaa.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
  <h4>Hello World!<>
</body>
</html>

在浏览器中输入地址127.0.0.1:8000/bb/。
如果没有实现目的,尝试在terminal中运行命令
python manage.py makemigrations
python manage.py migrate
python manage.py runserver

相关文章

网友评论

    本文标题:django:使用模板的简单例子

    本文链接:https://www.haomeiwen.com/subject/kskjictx.html