Django 实现Web便签

效果图

会用到的知识

  • 目录结构与URL路由注册
  • request与response对象
  • 模板基础与模板继承
  • ORM查询
  • 后台管理

实现步骤

  1. terminal 输入 django-admin startapp the_10回车
  1. 注册, 在 tutorial子文件夹settings.py INSTALLED_APPS 中括号添加 "the_10"
复制代码
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    "the_3",
    "the_5",
    "the_6",
    "the_7",
    "the_8",
    "the_9",
    "the_10",
]
  1. 路由 tutorial子文件夹 urls.py
复制代码
urlpatterns = [
    path('admin/', admin.site.urls),
    path('the_3/', include('the_3.urls')),
    path('the_4/', include('the_4.urls')),
    path('the_5/', include('the_5.urls')),
    path('the_7/', include('the_7.urls')),
    path('the_10/', include('the_10.urls')),
]
  1. the_10文件夹新建子文件夹 urls.py
python 复制代码
from django.urls import path
from .views import index


urlpatterns = [
    path('index/', index),
]
  1. the_10文件夹内的 views.py
python 复制代码
from django.shortcuts import render

# Create your views here.

def index(request):
    return render(request, "the_10/the_10_index.html")
  1. templates 文件夹创建 the_10子文件夹,再在the_10子文件夹 创建 the_10_index.html
html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>web便签</title>
</head>
<body>
    <h1>hello 2024</h1>
</body>
</html>
  1. 运行tutorial, 点击 http://127.0.0.1:8000/, 地址栏 https://127.0.0.1:8000/the_10/index/
  1. the_10_index.html 代码
python 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>web便签</title>
    <style>
        {# 归零#}
        *{
            padding: 0;
            margin: 0;
        }
        .appbar{
            height: 100px;
            color: rgb(92,53,21);
            {#给阴影#}
            text-shadow: 0 0 2px red;
            font-size: 60px;
            font-family: 黑体;
        }
        .main{
            display: flex;
        }
        .content{
            width: 90%;
            height: 700px;
        }
        .sidebar{
            width: 10%;
            height: 360px;
            font-family: 汉仪行楷简;
            font-size: 30px;
            {#文字上下展示,从右向左读#}
            writing-mode: vertical-rl; /* 从上到下 */
            text-shadow: 3px 5px 5px gray;
        }
        .footer{
            background: gray;
            text-align: center;
            color: white;
            padding: 5px 0;
        }
        .card1{
            float: left;
            width: 150px;
            height:150px;
            background: rgb(139 108 49);
            color: white;
            font-family: 黑体;
            display: flex;
            align-items: center;
            margin-left: 150px;
            margin-right: 20px;
            box-shadow: 1px 1px 10px 3px grey;
        }
        .card2{
            float: left;
            width: 150px;
            height:150px;
            background: rgb(139 108 49);
            color: white;
            font-family: 黑体;
            display: flex;
            align-items: center;
            box-shadow: 1px 1px 10px 3px grey;
        }
        .username{
            color: orangered;
            text-align: right;
        }
    </style>
</head>
<body>
{#页眉#}
    <div class="appbar">
        人生苦短,我用python
    </div>
{#主体#}
    <div class="main">
{#        左边#}
        <div class="content">
            <div class="card1">
                <div class="msg">
                    小明,记得好好吃饭哦!
                    <div class="username">
                    python大佬
                </div>
                </div>

            </div>
            <div class="card2">
                <div class="msg">
                    python大佬, 记得明天是项目截止日期!
                    <div class="username">
                    python大佬的老大
                </div>
                </div>
            </div>
        </div>
{#        右边#}
        <div class="sidebar">
            这世上本没有路, 走的人多了, 也就成了路!
        </div>
    </div>
{#页脚#}
<div class="footer">Copyright C 1970-2077 Python大佬 All Rights Reserved.</div>
</body>
</html>
  1. 刷新浏览器,实现效果
相关推荐
AI攻城狮1 分钟前
DeepSeek 的 Vision 能力要来了吗?
人工智能·后端·openai
迷藏49410 分钟前
# 发散创新:用Locust实现高并发场景下的精准压力测试与性能调优实战在现代微服务架构中,**接口稳定性与响应速度**已成为衡量
java·python·微服务·架构·压力测试
2401_8314194415 分钟前
如何防止MongoDB副本集被误初始化_副本集名称(replSetName)锁定
jvm·数据库·python
用户6224757584615 分钟前
面试官问我:"如何实现你项目中的这块代码."我说:"看好了."
后端
空中海15 分钟前
Nacos 2: Spring Boot Demo 实战
java·spring boot·后端
财经资讯数据_灵砚智能20 分钟前
基于全球经济类多源新闻的NLP情感分析与数据可视化(日间)2026年4月28日
人工智能·python·信息可视化·自然语言处理·ai编程
土豆.exe20 分钟前
Cast Attack:Java 中 Ghost Bits(幽灵比特)引发的新型安全威胁——Java 生态里被忽视的底层风险引发一系列绕过
java·python·安全
阿丰资源22 分钟前
基于Spring Boot的美容院管理系统(附源码+数据库+文档)
数据库·spring boot·后端
abc123456sdggfd27 分钟前
解决Socket图像传输中断问题:基于分块接收与可靠发送的完整教程
jvm·数据库·python
2401_8330336227 分钟前
SQL中RIGHT JOIN真的很少用吗_数据完整性检查与反向关联分析
jvm·数据库·python