GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — add index · Xu-Guo/python@68b50da

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • tango_with_django_project
    • db.sqlite3
    • populate_rango2.py
    • rango
      • views.py
    • templates/rango
      • index.html
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎tango_with_django_project/db.sqlite3‎

Copy file name to clipboard
0 Bytes
Binary file not shown.
Collapse file

‎tango_with_django_project/populate_rango2.py‎

Copy file name to clipboardExpand all lines: tango_with_django_project/populate_rango2.py
+16-8Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,47 @@ def populate():
1212

1313
add_page(c_id=3,
1414
title="Official Python Tutorial",
15-
url="http://docs.python.org/2/tutorial/")
15+
url="http://docs.python.org/2/tutorial/",
16+
views=800)
1617

1718
add_page(c_id=3,
1819
title="How to Think like a Computer Scientist",
19-
url="http://www.greenteapress.com/thinkpython/")
20+
url="http://www.greenteapress.com/thinkpython/",
21+
views=700)
2022

2123
add_page(c_id=3,
2224
title="Learn Python in 10 Minutes",
23-
url="http://www.korokithakis.net/tutorials/python/")
25+
url="http://www.korokithakis.net/tutorials/python/",
26+
views=600)
2427

2528
django_cat = add_cat("Django", 64, 32)
2629

2730
add_page(c_id=4,
2831
title="Official Django Tutorial",
29-
url="https://docs.djangoproject.com/en/1.5/intro/tutorial01/")
32+
url="https://docs.djangoproject.com/en/1.5/intro/tutorial01/",
33+
views=1000)
3034

3135
add_page(c_id=4,
3236
title="Django Rocks",
33-
url="http://www.djangorocks.com/")
37+
url="http://www.djangorocks.com/",
38+
views=500)
3439

3540
add_page(c_id=4,
3641
title="How to Tango with Django",
37-
url="http://www.tangowithdjango.com/")
42+
url="http://www.tangowithdjango.com/",
43+
views=900)
3844

3945
frame_cat = add_cat("Other Frameworks", 32, 16)
4046

4147
add_page(c_id=5,
4248
title="Bottle",
43-
url="http://bottlepy.org/docs/dev/")
49+
url="http://bottlepy.org/docs/dev/",
50+
views=400)
4451

4552
add_page(c_id=5,
4653
title="Flask",
47-
url="http://flask.pocoo.org")
54+
url="http://flask.pocoo.org",
55+
views=300)
4856

4957
# Print out what we have added to the user.
5058
for c in Category.objects.all():
Collapse file

‎tango_with_django_project/rango/views.py‎

Copy file name to clipboardExpand all lines: tango_with_django_project/rango/views.py
+9-4Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Create your views here.
77
from django.http import HttpResponse
88
# Import the Category model
9-
from rango.models import Category
9+
from rango.models import Category, Page
1010
import logging
1111
logging.basicConfig(level=logging.DEBUG)
1212

@@ -29,8 +29,12 @@ def index(request):
2929
# Order the categories by no. likes in descending order.
3030
# Retrieve the top 5 only - or all if less than 5.
3131
# Place the list in our context_dict dictionary which will be passed to the template engine.
32+
context_dict = {}
3233
category_list = Category.objects.order_by('-likes')[:5]
33-
context_dict = {'categories': category_list}
34+
context_dict['categories'] = category_list
35+
36+
page_list = Page.objects.order_by('-views')[:5]
37+
context_dict['pages'] = page_list
3438

3539
# Render the response and send it back!
3640
return render(request, 'rango/index.html', context_dict)
@@ -43,7 +47,7 @@ def about(request):
4347

4448

4549
def category(request, category_name_slug):
46-
logging.debug("category_name_slug:{0}".format(category_name_slug))
50+
logging.debug("category_name_slug-------------{0}".format(category_name_slug))
4751
# Create a context dictionary which we can pass to the template rendering engine.
4852
context_dict = {}
4953

@@ -64,7 +68,8 @@ def category(request, category_name_slug):
6468
# We'll use this in the template to verify that the category exists.
6569
context_dict['category'] = category
6670

67-
logging.debug('pages:{0}'.format)
71+
logging.debug('pages-------------{0}'.format(pages))
72+
logging.debug('category-------------{0}'.format(category))
6873

6974
except Category.DoesNotExist:
7075
# We get here if we didn't find the specified category.
Collapse file

‎tango_with_django_project/templates/rango/index.html‎

Copy file name to clipboard
+29-18Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,35 @@
11
<!DOCTYPE html>
22
<html>
3+
<head>
4+
<title>Rango</title>
5+
</head>
36

4-
<head>
5-
<title>Rango</title>
6-
</head>
7+
<body>
8+
<h1>Rango says..hello world!</h1>
79

8-
<body>
9-
<h1>Rango says...hello world!</h1>
10+
<h2>Top 5 Category</h2>
11+
{% if categories %}
12+
<ul>
13+
{% for category in categories %}
14+
<!-- Following line changed to add an HTML hyperlink -->
15+
<li><a href="/rango/category/{{ category.slug }}">{{ category.name }}</a></li>
16+
{% endfor %}
17+
</ul>
18+
{% else %}
19+
<strong>There are no categories present.</strong>
20+
{% endif %}
1021

11-
{% if categories %}
12-
<ul>
13-
{% for category in categories %}
14-
<li>{{ category.name }}</li>
15-
{% endfor %}
16-
</ul>
17-
{% else %}
18-
<strong>There are no categories present.</strong>
19-
{% endif %}
20-
21-
<a href="/rango/about/">About</a>
22-
</body>
22+
<h2>Top 5 Page</h2>
23+
{% if pages %}
24+
<ul>
25+
{% for page in pages %}
26+
<li>{{ page.title }}</li>
27+
{% endfor %}
28+
</ul>
29+
{% else %}
30+
<strong>There are no pages present.</strong>
31+
{% endif %}
2332

24-
</html>
33+
34+
</body>
35+
</html>

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.