django locals()

@permission_verify()
def edit(request):
    temp_name = "navi/navi-header.html"
    if request.method == 'GET':
        item = request.GET.get("id")
        obj = navi.objects.get(id=item)
    return render(request, "navi/edit.html", locals())


def year_archive(request, year):
    a_list = Article.objects.filter(pub_date__year=year)
    context = {'year': year, 'article_list': a_list}
    return render(request, 'news/year_archive.html', context)

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^learn/', learnview.index),
    url(r'^add/', learnview.add),
    url(r'^articles/',include("news.urls"))
]



urlpatterns = [
    url(r'([0-9]{4})/', views.year_archive),



node2:/app/mysite/news/templates/news#cat year_archive.html 

{% block title %}Articles for {{ year }}{% endblock %}

{% block content %}
<h1>Articles for {{ year }}</h1>

{% for article in article_list %}
    <p>{{ article.headline }}</p>
    <p>By {{ article.reporter.full_name }}</p>
    <p>Published {{ article.pub_date|date:"F j, Y" }}</p>
{% endfor %}
{% endblock %}



DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'merry',
'USER': 'root',
'PASSWORD': '1234567',
'HOST': '192.168.137.3',
'PORT': '3306',
}
}


mysql> select * from news_article;
+----+------------+----------------+---------+-------------+
| id | pub_date   | headline       | content | reporter_id |
+----+------------+----------------+---------+-------------+
|  1 | 2018-07-12 | Django is cool | Yeah.   |           1 |
|  2 | 2018-08-13 | aaaa           | bbb     |           1 |
|  3 | 2017-08-13 | 测试           | 杭州    |           1 |
+----+------------+----------------+---------+-------------+
3 rows in set (0.00 sec)
原文地址:https://www.cnblogs.com/hzcya1995/p/13349008.html