Django学习(1)一首情诗
2023-09-27 14:23:14 时间
Django是Python中Web开发的最有代表性的框架之一。本文将简单介绍如何入门Django开发。
首先确保你的linux系统已安装django模块。打开Python3,利用以下命令可找到django所在目录:
>>> import django >>> print(django.__path__)
笔者显示的是:
['/usr/lib/python3/dist-packages/django']
接下来开始django开发!首先切换到django目录,新建poem项目:
django-admin.py startproject poem
输入tree poem,查看poem项目的树结构:
在urls.py的urlpatterns列表中添加:
url(r'^$', 'poem.views.output'),
在/poem/poem文件夹下,创建views.py文件,输入代码:
from django.http import HttpResponse def output(request): title = "<h1>When You Are Old</h1>" author = "<h2>William Butler Yeats</h2>" content = """ When you are old and grey and full of sleep,<br/> And nodding by the fire, take down this book,<br/> And slowly read, and dream of the soft look<br/> Your eyes had once, and of their shadows deep;<br/> How many loved your moments of glad grace,<br/> And loved your beauty with love false or true,<br/> But one man loved the pilgrim soul in you,<br/> And loved the sorrows of your changing face;<br/> And bending down beside the glowing bars,<br/> Murmur, a little sadly, how love fled<br/> And paced upon the mountains overhead<br/> And hid his face amid a crowd of stars.<br/> """ return HttpResponse([title, author, content])
进入poem文件夹,输入命令:
python3 manage.py runserver 8000
打开浏览器,输入localhost:8000,页面如下图:
这样我们就完成了一个简单的django项目的开发。期待下期分享~~
本次分享到此结束,欢迎大家批评与交流~~
相关文章
- 66.基于Django学习会话技术
- Django之破解数独
- Django学习笔记之Queryset的高效使用
- Django学习笔记之Django ORM Aggregation聚合详解
- Django学习笔记之Django QuerySet的方法
- Django学习笔记之Django视图View
- Django学习笔记之使用 Django项目开发框架
- Django学习笔记之Web框架由浅入深和第一个Django实例
- Django返回json数据
- Django中使用POST提交和接收数据
- Django 实战 之 搭项目(正在更新)
- 【Django】如何按天 小时等查询统计?
- The Definitive Guide To Django 2 学习笔记(九) 第五章 模型 (一)数据库访问
- The Definitive Guide To Django 2 学习笔记(二) 第二个View 动态内容
- Django 聚合与查询集API实现侧边栏
- Django 练习班级管理系统五 -- 查看老师列表
- django 模板实现换行
- django静态html中做动态变化
- django view使用学习记录
- django form使用学习记录
- Django 可视化Web展示 学习
- 从命令行运行django数据库操作
- DJANGO:从当前用户的所属用户组里查找其所拥有的权限矩阵
- 三十八、python学习之Django框架(一):入门,介绍,设计模式,环境搭建,项目创建,基本配置,创建视图,静态文件,路由与反解析,App应用配置
- 四十八、python学习之Django框架(DRF框架四):认证、权限、限流、过滤、排序、分页、异常处理、自动生成接口文档