借我杀死庸碌的情怀
初学者,一切都是个开始和摸索
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配合使用提升开发效率...
Django中的使用新建一个文件夹专门存放模板文件,命名为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/'),)
- 为了显示电影数据:修改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. 编程感悟
- 如果不是你遇到的实际问题,看任何实际的文章都存在着知识的盲区。
- 想要把一个东西说出来和写出来,和你感觉会,不是一码事。
- 这是个需要不断更新知识的时代,每天都存在着接触或者被动接触新东西,需要抓住自己的知识体系不断构建,不然易陷入贪多还不会的地步。
- 学会一点技术,重复是个少不了的技能。
- 摸索需要极大的成本,假如身边有牛人,千万别放过学习的机会...
在平坦的路上曲折前行...致:美貌大王 --许岑

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version
Visual web development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

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