Skip to content

Commit 31fabbc

Browse files
authored
Merge pull request #2571 from v-thepet/cats-python
fix code language labels
2 parents f518e21 + cd31d60 commit 31fabbc

File tree

2 files changed

+104
-104
lines changed

2 files changed

+104
-104
lines changed

docs/python/learn-flask-visual-studio-step-04-full-flask-project-template.md

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -161,63 +161,63 @@ To enable Jade, the project template first includes the pyjade package in `requi
161161

162162
The app's `__init__.py` file contains a line to
163163

164-
```python
165-
app.jinja_env.add_extension('pyjade.ext.jinja.PyJadeExtension')
166-
```
164+
```python
165+
app.jinja_env.add_extension('pyjade.ext.jinja.PyJadeExtension')
166+
```
167167
In the `templates` folder, you see `.jade` files instead of `.html` templates, and the views in `views.py` refer to these files in their calls to `flask.render_template`. Otherwise the views code is the same.
168168

169169
Opening one of the `.jade` files, you can see the more succinct expression of a template. For example, here's the contents of `templates/layout.jade` as created by the "Flask/Jade Web Project" template:
170170

171-
```jade
172-
doctype html
173-
html
174-
head
175-
meta(charset='utf-8')
176-
meta(name='viewport', content='width=device-width, initial-scale=1.0')
177-
title #{title} - My Flask/Jade Application
178-
link(rel='stylesheet', type='text/css', href='/static/content/bootstrap.min.css')
179-
link(rel='stylesheet', type='text/css', href='/static/content/site.css')
180-
script(src='/static/scripts/modernizr-2.6.2.js')
181-
body
182-
.navbar.navbar-inverse.navbar-fixed-top
183-
.container
184-
.navbar-header
185-
button.navbar-toggle(type='button', data-toggle='collapse', data-target='.navbar-collapse')
186-
span.icon-bar
187-
span.icon-bar
188-
span.icon-bar
189-
a.navbar-brand(href='/') Application name
190-
.navbar-collapse.collapse
191-
ul.nav.navbar-nav
192-
li
193-
a(href='/') Home
194-
li
195-
a(href='/about') About
196-
li
197-
a(href='/contact') Contact
198-
.container.body-content
199-
block content
200-
hr
201-
footer
202-
p © #{year} - My Flask/Jade Application
203-
204-
script(src='/static/scripts/jquery-1.10.2.js')
205-
script(src='/static/scripts/bootstrap.js')
206-
script(src='/static/scripts/respond.js')
207-
208-
block scripts
209-
```
171+
```jade
172+
doctype html
173+
html
174+
head
175+
meta(charset='utf-8')
176+
meta(name='viewport', content='width=device-width, initial-scale=1.0')
177+
title #{title} - My Flask/Jade Application
178+
link(rel='stylesheet', type='text/css', href='/static/content/bootstrap.min.css')
179+
link(rel='stylesheet', type='text/css', href='/static/content/site.css')
180+
script(src='/static/scripts/modernizr-2.6.2.js')
181+
body
182+
.navbar.navbar-inverse.navbar-fixed-top
183+
.container
184+
.navbar-header
185+
button.navbar-toggle(type='button', data-toggle='collapse', data-target='.navbar-collapse')
186+
span.icon-bar
187+
span.icon-bar
188+
span.icon-bar
189+
a.navbar-brand(href='/') Application name
190+
.navbar-collapse.collapse
191+
ul.nav.navbar-nav
192+
li
193+
a(href='/') Home
194+
li
195+
a(href='/about') About
196+
li
197+
a(href='/contact') Contact
198+
.container.body-content
199+
block content
200+
hr
201+
footer
202+
p © #{year} - My Flask/Jade Application
203+
204+
script(src='/static/scripts/jquery-1.10.2.js')
205+
script(src='/static/scripts/bootstrap.js')
206+
script(src='/static/scripts/respond.js')
207+
208+
block scripts
209+
```
210210

211211
And here's the contents of `templates/about.jade`, showing the use of `#{ <name>}` for placeholders:
212212

213-
```jade
214-
extends layout
213+
```jade
214+
extends layout
215215
216-
block content
217-
h2 #{title}.
218-
h3 #{message}
219-
p Use this area to provide additional information.
220-
```
216+
block content
217+
h2 #{title}.
218+
h3 #{message}
219+
p Use this area to provide additional information.
220+
```
221221

222222
Feel free to experiment with both Jinja and Jade syntaxes to see which one works best for you.
223223

docs/python/learn-flask-visual-studio-step-05-polls-flask-web-project-template.md

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -73,35 +73,35 @@ As noted before. much of what's in a project created from the "Polls Flask Web P
7373

7474
The data models for the app are Python classes named Poll and Choice, which are defined in `models/__init__.py`. A Poll represents a question, for which a collection of Choice instances represent the available answers. A Poll also maintains the total number of votes (for any choice) and a method to calculate statistics that are used to generate views:
7575

76-
```python
77-
class Poll(object):
78-
"""A poll object for use in the application views and repository."""
79-
def __init__(self, key=u'', text=u''):
80-
"""Initializes the poll."""
81-
self.key = key
82-
self.text = text
83-
self.choices = []
84-
self.total_votes = None
85-
86-
def calculate_stats(self):
87-
"""Calculates some statistics for use in the application views."""
88-
total = 0
89-
for choice in self.choices:
90-
total += choice.votes
91-
for choice in self.choices:
92-
choice.votes_percentage = choice.votes / float(total) * 100 \
93-
if total > 0 else 0
94-
self.total_votes = total
95-
96-
class Choice(object):
97-
"""A poll choice object for use in the application views and repository."""
98-
def __init__(self, key=u'', text=u'', votes=0):
99-
"""Initializes the poll choice."""
100-
self.key = key
101-
self.text = text
102-
self.votes = votes
103-
self.votes_percentage = None
104-
```
76+
```python
77+
class Poll(object):
78+
"""A poll object for use in the application views and repository."""
79+
def __init__(self, key=u'', text=u''):
80+
"""Initializes the poll."""
81+
self.key = key
82+
self.text = text
83+
self.choices = []
84+
self.total_votes = None
85+
86+
def calculate_stats(self):
87+
"""Calculates some statistics for use in the application views."""
88+
total = 0
89+
for choice in self.choices:
90+
total += choice.votes
91+
for choice in self.choices:
92+
choice.votes_percentage = choice.votes / float(total) * 100 \
93+
if total > 0 else 0
94+
self.total_votes = total
95+
96+
class Choice(object):
97+
"""A poll choice object for use in the application views and repository."""
98+
def __init__(self, key=u'', text=u'', votes=0):
99+
"""Initializes the poll choice."""
100+
self.key = key
101+
self.text = text
102+
self.votes = votes
103+
self.votes_percentage = None
104+
```
105105

106106
These data models are generic abstractions that allow the app's views to work against different types of backing data stores, which are described in the next step.
107107

@@ -184,32 +184,32 @@ The following steps add support for a different data store than the three provid
184184

185185
Initially, any chosen data store contains no polls, so the app's home page shows the message "No polls available" along with the **Create Sample Polls** button. Once you select the button, however, the view changes to display available polls. This switch happens through conditional tags in `templates\index.html` (some blank lines omitted for brevity):
186186

187-
```html
188-
{% extends "layout.html" %}
189-
{% block content %}
190-
<h2>{{title}}.</h2>
191-
192-
{% if polls %}
193-
<table class="table table-hover">
194-
<tbody>
195-
{% for poll in polls %}
196-
<tr>
197-
<td>
198-
<a href="/poll/{{poll.key}}">{{poll.text}}</a>
199-
</td>
200-
</tr>
201-
{% endfor %}
202-
</tbody>
203-
</table>
204-
{% else %}
205-
<p>No polls available.</p>
206-
<br />
207-
<form action="/seed" method="post">
208-
<button class="btn btn-primary" type="submit">Create Sample Polls</button>
209-
</form>
210-
{% endif %}
211-
{% endblock %}
212-
```
187+
```html
188+
{% extends "layout.html" %}
189+
{% block content %}
190+
<h2>{{title}}.</h2>
191+
192+
{% if polls %}
193+
<table class="table table-hover">
194+
<tbody>
195+
{% for poll in polls %}
196+
<tr>
197+
<td>
198+
<a href="/poll/{{poll.key}}">{{poll.text}}</a>
199+
</td>
200+
</tr>
201+
{% endfor %}
202+
</tbody>
203+
</table>
204+
{% else %}
205+
<p>No polls available.</p>
206+
<br />
207+
<form action="/seed" method="post">
208+
<button class="btn btn-primary" type="submit">Create Sample Polls</button>
209+
</form>
210+
{% endif %}
211+
{% endblock %}
212+
```
213213

214214
The `polls` variable in the template comes from a call to `repository.get_polls`, which returns nothing until the data store is initialized.
215215

0 commit comments

Comments
 (0)