search
HomeWeb Front-endHTML TutorialDjango: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配合使用提升开发效率...
  • 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. 编程感悟

  1. 如果不是你遇到的实际问题,看任何实际的文章都存在着知识的盲区。
  2. 想要把一个东西说出来和写出来,和你感觉会,不是一码事。
  3. 这是个需要不断更新知识的时代,每天都存在着接触或者被动接触新东西,需要抓住自己的知识体系不断构建,不然易陷入贪多还不会的地步。
  4. 学会一点技术,重复是个少不了的技能。
  5. 摸索需要极大的成本,假如身边有牛人,千万别放过学习的机会...

在平坦的路上曲折前行...致:美貌大王 --许岑

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?Mar 04, 2025 pm 12:32 PM

The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

How do I use HTML5 form validation attributes to validate user input?How do I use HTML5 form validation attributes to validate user input?Mar 17, 2025 pm 12:27 PM

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

What are the best practices for cross-browser compatibility in HTML5?What are the best practices for cross-browser compatibility in HTML5?Mar 17, 2025 pm 12:20 PM

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

How to efficiently add stroke effects to PNG images on web pages?How to efficiently add stroke effects to PNG images on web pages?Mar 04, 2025 pm 02:39 PM

This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

What is the purpose of the <datalist> element?What is the purpose of the <datalist> element?Mar 21, 2025 pm 12:33 PM

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

What is the purpose of the <progress> element?What is the purpose of the <progress> element?Mar 21, 2025 pm 12:34 PM

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

How do I use the HTML5 <time> element to represent dates and times semantically?How do I use the HTML5 <time> element to represent dates and times semantically?Mar 12, 2025 pm 04:05 PM

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

What is the purpose of the <meter> element?What is the purpose of the <meter> element?Mar 21, 2025 pm 12:35 PM

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

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment