django总结

来源:互联网 发布:淘宝主店分店 编辑:程序博客网 时间:2024/05/16 02:33

render函数引入参数

index_page = render(request, 'first_web_2.html', context)

models中的数据库代码改动,合并数据库的操作

python manage.py makemigrationspython manage.py migrate

把html中引用的css路径更换成模板标签的方法

<link rel="stylesheet" href="{% static 'css/semantic.css' %}" media="screen" title="no title" charset="utf-8">

for循环

{% for article in article_list %}...{% endfor %}

模板变量

<h3 class="ui header title">{{ article.headline }}</h3>

填入时间
2015-10-12
model里增加

class = Article(models.Model):    date = models.DateField(auto_now=True)

html里增加

<span class="grey">{{ article.date|date:"YYYY-MM-DD" }}</span>

context上下文的运行机制是:把数据传递到模板,从而可以进行渲染。


理解queryset = request.GET.get(‘tag’)
request和GET相当于是字典套字典的关系:

request:{GET:{'q':1,'tag':life},GET:{'q':2,'tag':tech},}

request.GET.get()={}这样的结构就相当于是车.轮子.转
轮子(GET)是车(request)下面的一个字典,转(get)是轮子(GET)的方法。