Python实战:webapp开发30步之一

Python 版本2.7
安装开发Web app需要的第三方库
前端模板引擎jinja2

$pip install jinja2

MYSQL 5.x数据库,下载并安装,务必牢记root口令,为避免遗忘,我将密码设为password。

MySQL的Python驱动程序MySQL-connector-python.

$pip install MySQL-connector-python

项目结构
选择一个工作目录,创建如下的目录结构

awesome-python-webapp/ <– 根目录
|
+- backup/ <– 备份目录
|
+- conf/ <– 配置文件
|
+- dist/ <– 打包目录
|
+- www/ <– Web目录,存放.py文件
| |
| +- static/ <– 存放静态文件
| |
| +- templates/ <– 存放模板文件
|
+- LICENSE <– 代码LICENSE

同时创建Git仓库并同步至github,保证代码修改安全。

我使用的开发工具是Pycharm。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这里提供一个简单的WebApp代码示例,使用HTML、CSS和JavaScript编写。该WebApp是一个简单的待办事项列表,用户可以添加、删除和标记已完成的任务。 HTML代码: ``` <!DOCTYPE html> <html> <head> <title>Todo List</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div class="wrapper"> <h1>Todo List</h1> <input type="text" id="new-task" placeholder="Add new task"> <button id="add-task">Add</button> <ul id="task-list"></ul> </div> <script src="app.js"></script> </body> </html> ``` CSS代码: ``` body { font-family: Arial, sans-serif; } .wrapper { max-width: 500px; margin: 0 auto; padding: 20px; background-color: #f2f2f2; border-radius: 10px; box-shadow: 0 0 10px rgba(0,0,0,0.2); } h1 { text-align: center; } input[type="text"] { padding: 10px; width: 70%; border-radius: 5px; border: none; box-shadow: 0 0 5px rgba(0,0,0,0.1) inset; } button { padding: 10px; background-color: #007bff; color: #fff; border: none; border-radius: 5px; cursor: pointer; } button:hover { background-color: #0062cc; } ul { list-style: none; padding: 0; margin: 0; } li { padding: 10px; margin: 5px 0; background-color: #fff; border-radius: 5px; box-shadow: 0 0 5px rgba(0,0,0,0.1); display: flex; justify-content: space-between; align-items: center; } li.completed { background-color: #d7ffd7; } li.completed .task-text { text-decoration: line-through; color: #999; } ``` JavaScript代码: ``` const newTaskInput = document.getElementById('new-task'); const addTaskButton = document.getElementById('add-task'); const taskList = document.getElementById('task-list'); function addTask() { if (newTaskInput.value.trim() === '') { return; } const taskText = newTaskInput.value.trim(); const taskItem = document.createElement('li'); const taskTextElement = document.createElement('span'); const deleteButton = document.createElement('button'); const completeButton = document.createElement('button'); taskTextElement.textContent = taskText; deleteButton.textContent = 'Delete'; completeButton.textContent = 'Complete'; deleteButton.addEventListener('click', deleteTask); completeButton.addEventListener('click', completeTask); taskItem.appendChild(taskTextElement); taskItem.appendChild(deleteButton); taskItem.appendChild(completeButton); taskList.appendChild(taskItem); newTaskInput.value = ''; } function deleteTask(event) { event.target.parentNode.remove(); } function completeTask(event) { event.target.parentNode.classList.toggle('completed'); } addTaskButton.addEventListener('click', addTask); ``` 以上代码实现了一个简单的WebApp,可以自由添加、删除和标记任务。当用户点击“完成”按钮时,任务将被标记为已完成,并在列表项上应用“completed”类。当用户点击“删除”按钮时,任务将被删除。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值