django框架初体验 --- 返回静态页面

django框架初体验 — 返回静态页面
效果图:
在这里插入图片描述
1、在templates中新建html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>电视剧页面</title>
    <style>
        .tv {
      
      
            width: 600px;
            height: 400px;
            margin: 40px auto;
            background-color: lightcoral;
            color: red;
            font-size: 50px;
            line-height: 400px;
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="tv">TV</div>
</body>
</html>

2、在views.py中新建函数:

def tv(request):
    '''
    返回tv的页面
    :param request:
    :return:
    '''
    return render(request, 'tv.html')

3、在urls.py中添加path:

from app01.views import tv

urlpatterns = [
    path('admin/', admin.site.urls),
    path('tv/', tv),
]

4、在命令行中输入:python manage.py runserver ,在浏览器中访问生成的地址:http://127.0.0.1:8000/tv/

猜你喜欢

转载自blog.csdn.net/weixin_49981930/article/details/128720785