Django:web框架的学习(3)_html/css_WEB-ITnose
借我杀死庸碌的情怀
初学者,一切都是个开始和摸索
To learn Django step by step.
001:Django:web框架的学习002:Django:web框架的学习(2)
核心知识:
- 再次强化开发步骤和知识
- 简易的HTML和CSS语法
- 数据库操作
- 模板的使用
1: 目标
先显示最终效果图:这是个包含背景颜色的网页,不是水印。
1465024645455.png
- Wechat : 显示微信账号
- Weibo:直接跳转至微博平台
- Github: 直接跳转至Github平台
- 简书: 直接跳转至简书平台
- 更多:跳转至抓取的豆瓣电影Top250,后页面显示的部分:
1465025610484.png
2:重申开发步骤
- 创建APP
- 编辑视图文件
- 配置url
- 编辑模型文件定义数据库
- 编辑模板文件
3:定义数据库文件
- 账号数据表:对应于:wechat, 简书,github 等
class Message(models.Model): Id_name = models.CharField(max_length=10) Id_user = models.CharField(max_length=10) Id_url = models.CharField(max_length=60) Id_des = models.TextField(max_length=60) def __str__(self): return self.Id_user# 包含名称,账号,链接,介绍几个字段
- 电影数据:这里不讲述数据如何抓取:爬虫看这里
class Film(models.Model): Film_name = models.CharField(max_length=20) Film_director = models.CharField(max_length=10) Film_rate = models.FloatField(max_length=5) Film_number = models.CharField(max_length=10) Film_url = models.CharField(max_length=30) Film_describe = models.TextField(max_length=60) def __str__(self): return self.Film_name# 定义5个字段和相应数据类型## 确保上述数据表中存在数据
4:模板文件
模板文件都是些前端知识,好吧,我不太会...
大致的内容有:
- HTML的元素,属性,结构之类的
- CSS层叠样式:修饰HTML文件中的内容的形式
举例:
- HTML
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>谢小路</title></head><div></div><body><h1 id="Hello-world">Hello world!</h1></body></html># HTML文件长这样.
CSS
nav{ background-color: #000000; height: 50px;}#banner{ background: #CCCCCC; height: 600px;}# 定义了背景颜色和高度# HTML 和CSS配合使用提升开发效率...
Copy after loginDjango中的使用新建一个文件夹专门存放模板文件,命名为templates,文件夹下可以创建文件夹以APP名称存放模板文件这里我创建了两个APP,一个名为one,一个为two其中one/film.html文件下显示的是:上文中更多显示的电影数据two/index.html文件显示的是:首页信息,即上文第一张图显示
|---templates|---templates/one/film.html|---templates/two/index.html
- 设置模板文件路径setting.py
TEMPLATES_DIR = ( os.path.join(BASE_DIR, 'templates/one/'), os.path.join(BASE_DIR, 'templates/two/'),)
Copy after login - 为了显示电影数据:修改one下的视图文件:views.py , film.html模板文件
def film(request): film = Film.objects.order_by("id") return render(request, 'one/film.html', {"Film": film}) pass
- 为了显示账户信息等数据:修改two下视图文件:views.py index.html模板文件
def des(request): message = Message.objects.order_by("id") return render(request, 'two/index.html' , {"Message": message})
- 配置url
urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^film', film), # 这个显示电影数据 url(r'', des), # 这个显示首页信息]
5. Django常用指令
- django-admin.py startproject [filename] # 创建新项目
- python manage.py runserver # 启动web服务
- python manage.py startapp [APPNAME] # 创建web APP
- python manage.py makemigrations
- python manage.py migrate
- python manage.py shell
- python manage.py createsuperuser # 创建后台超级用户
6. 编程感悟
- 如果不是你遇到的实际问题,看任何实际的文章都存在着知识的盲区。
- 想要把一个东西说出来和写出来,和你感觉会,不是一码事。
- 这是个需要不断更新知识的时代,每天都存在着接触或者被动接触新东西,需要抓住自己的知识体系不断构建,不然易陷入贪多还不会的地步。
- 学会一点技术,重复是个少不了的技能。
- 摸索需要极大的成本,假如身边有牛人,千万别放过学习的机会...
在平坦的路上曲折前行...致:美貌大王 --许岑

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

The article discusses the <iframe> tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.
