python自动化之(django)(2)

1、创建应用

python manage.py startapp apitest

这里还是从上节开始也就是命令行在所谓的autotest目录下来输入

然后可以清楚的看到

多了一个文件夹

2、创建视图

在views中加入test函数(所建应用下)

复制代码
from django.http import HttpResponse
复制代码
def test(request):
    return HttpResponse("hello test")

3、创建映射

在autotest/urls.py中添加以下代码

复制代码
from apitest import views
urlpatterns = [
    path('test/', views.test),

](记得是加进去不是复制粘贴就可以)

4、创建模板

在apitest下创建templates文件夹然后创建login.html

加入内容

复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html" charset="UTF-8">
    <title>login</title>
</head>
<body>
<h1>login</h1>
<form method="post" action="/login/">
    {% csrf_token %}
    <br><input name="username" type="text" placeholder="username">
    <br><input name="password" type="text" placeholder="password">
    {{error}}<br>
    <br><button name ="submit" type="submit">submit</button>

</form>
</body>
</html>

然后依照前面步骤创建映射和函数(函数有略微不同如下:)

复制代码
def login(request):
    return render(request,'login.html')

最后成果:

因为没有加数据之类的后端内容所以功能没办法正常实现后面会提到。

相关推荐
likfishdn10 分钟前
Linux的文件与目录管理
linux·运维·服务器
chian-ocean30 分钟前
Linux 文件缓冲区:高效数据访问的幕后推手
linux·运维·服务器
加油=^_^=32 分钟前
【Linux】进程优先级 | 进程调度(三)
linux·运维·服务器
元气满满的热码式1 小时前
Docker数据卷操作实战
linux·运维·docker·云原生·容器
北京耐用通信1 小时前
航空装配自动化神器Ethercat转profient网关搭配机器人精准控制
运维·机器人·自动化
吃汤圆的抹香鲸2 小时前
Rider 安装包 绿色版 Win/Mac/Linux 适合.NET和游戏开发者使用 2025全栈开发终极指南:从零配置到企业级实战
linux·运维·windows·sql·游戏·macos·.net
崔lc4 小时前
linux中安装部署Jenkins,成功构建springboot项目详细教程
运维·jenkins
luojiaao4 小时前
【Jenkins】个人向-Jenkinsfile如何写
运维·jenkins
wanhengidc8 小时前
单线服务器和双线服务器分别是指什么?
运维·服务器
SuperherRo10 小时前
自动化反编译微信小程序工具-e0e1-wx
微信小程序·自动化·hook·反编译