Skip to content

Commit 02749ca

Browse files
committedFeb 7, 2019
Chapter 2 - Recipe 'Bootstrap layout'
1 parent d4a2e4e commit 02749ca

File tree

8 files changed

+70
-23
lines changed

8 files changed

+70
-23
lines changed
 

‎app.py

-23
This file was deleted.

‎my_app/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from flask import Flask
2+
from my_app.hello.views import hello
3+
4+
app = Flask(__name__)
5+
app.register_blueprint(hello)

‎my_app/hello/__init__.py

Whitespace-only changes.

‎my_app/hello/models.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
MESSAGES = {
2+
'default': 'Hello to the World of Flask!',
3+
}

‎my_app/hello/views.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from flask import Blueprint
2+
from flask import render_template, request
3+
from my_app.hello.models import MESSAGES
4+
5+
hello = Blueprint('hello', __name__)
6+
7+
8+
@hello.route('/')
9+
@hello.route('/hello')
10+
def hello_world():
11+
user = request.args.get('user', 'Shalabh')
12+
return render_template('index.html', user=user)
13+
14+
15+
@hello.route('/show/<key>')
16+
def get_message(key):
17+
return MESSAGES.get(key) or "%s not found!" % key
18+
19+
20+
@hello.route('/add/<key>/<message>')
21+
def add_or_update_message(key, message):
22+
MESSAGES[key] = message
23+
return "%s Added/Updated" % key

‎my_app/templates/index.html

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<html>
2+
<head>
3+
<title>Flask Framework Cookbook</title>
4+
</head>
5+
<body>
6+
<h1>Hello {{ user }}!</h1>
7+
<p>Welcome to the world of Flask!</p>
8+
</body>
9+
</html>

‎run.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from my_app import app
2+
app.run(debug=True)

‎setup.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python
2+
# -*- coding: UTF-8 -*-
3+
import os
4+
from setuptools import setup
5+
6+
setup(
7+
name = 'my_app',
8+
version='1.0',
9+
license='GNU General Public License v3',
10+
author='Shalabh Aggarwal',
11+
author_email='contact@shalabhaggarwal.com',
12+
description='Hello world application for Flask',
13+
packages=['my_app'],
14+
platforms='any',
15+
install_requires=[
16+
'flask',
17+
],
18+
classifiers=[
19+
'Development Status :: 4 - Beta',
20+
'Environment :: Web Environment',
21+
'Intended Audience :: Developers',
22+
'License :: OSI Approved :: GNU General Public License v3',
23+
'Operating System :: OS Independent',
24+
'Programming Language :: Python',
25+
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
26+
'Topic :: Software Development :: Libraries :: Python Modules'
27+
],
28+
)

0 commit comments

Comments
 (0)
Please sign in to comment.