1. project 下同名文件夹的setting.py 用于设置一些通用属性。
2. 完成的APP需要添加到setting.py 里的INSTALLED_APPS里
3. 每个APP代表一个PROJECT里的不同功能模块。不要把一个网站所有功能做到一个APP里。
4. 使用 python -m venv xxx 指令可创建虚拟环境
5. python manage.py
- migrate: 用于执行迁移动作
- makemigrations: 基于当前的model创建新的迁移策略文件
- sqlmigrate: 显示迁移的SQL语句
6. urls.py 定义网站的url结构
7. views.py 定义后台逻辑结构
8. https://docs.djangoproject.com/en/2.0/ref/contrib/humanize/ 自带的过滤器 语法 : {{ time|naturaltime }}
9. views 里的xxx.html 是templates里面的文件名,而urls里的正则表达式要和html相应的超链接地址匹配。
10. 可将几个模板通用的部分(如页面头部的一系列引用和声明)放在base_generic.html中,然后在各个不同页面用以下方法引用。
Templates¶
A template is simply a text file. It can generate any text-based format (HTML, XML, CSV, etc.).
A template contains variables, which get replaced with values when the template is evaluated, and tags, which control the logic of the template.
Below is a minimal template that illustrates a few basics. Each element will be explained later in this document.
{% extends "base_generic.html" %}
{% block title %}{{ section.title }}{% endblock %}
{% block content %}
<h1>{{ section.title }}</h1>
{% for story in story_list %}
<h2>
<a href="{{ story.get_absolute_url }}">
{{ story.headline|upper }}
</a>
</h2>
<p>{{ story.tease|truncatewords:"100" }}</p>
{% endfor %}
{% endblock %}