Skip to content

Updates per Adrian #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "HelloFlask/app.py"
"FLASK_APP": "hello_app/app.py"
},
"args": [
"run",
Expand Down Expand Up @@ -122,4 +122,4 @@
]
}
]
}
}
5 changes: 0 additions & 5 deletions HelloFlask/app.py

This file was deleted.

4 changes: 0 additions & 4 deletions HelloFlask/templates/about.html

This file was deleted.

4 changes: 0 additions & 4 deletions HelloFlask/templates/contact.html

This file was deleted.

11 changes: 0 additions & 11 deletions HelloFlask/templates/hello_there.html

This file was deleted.

4 changes: 0 additions & 4 deletions HelloFlask/templates/home.html

This file was deleted.

31 changes: 0 additions & 31 deletions HelloFlask/views.py

This file was deleted.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
This sample contains the completed program from the tutorial, [Using Flask in Visual Studio Code](https://code.visualstudio.com/docs/python/tutorial-flask). Intermediate steps are not included.

Contributions to the sample are welcome. When submitting changes, also consider submitting matching changes to the tutorial, the source file for which is [tutorial-flask.md](https://github.com/Microsoft/vscode-docs/blob/master/docs/python/tutorial-flask.md).


# Contributing

Expand Down
2 changes: 1 addition & 1 deletion HelloFlask/__init__.py → hello_app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from flask import Flask
app = Flask(__name__)
app = Flask(__name__)
5 changes: 5 additions & 0 deletions hello_app/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from hello_app import app
from hello_app import views

# Time-saver: output a URL to the VS Code terminal so you can easily Ctrl+click to open a browser
# print('http://127.0.0.1:5000/hello/VSCode')
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions hello_app/templates/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "layout.html" %}
{% block title %}
About us
{% endblock %}
{% block content %}
<p>About page for the Visual Studio Code Flask tutorial.</p>
{% endblock %}
7 changes: 7 additions & 0 deletions hello_app/templates/contact.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "layout.html" %}
{% block title %}
Contact us
{% endblock %}
{% block content %}
<p>Contact page for the VIsual Studio Code Flask tutorial.</p>
{% endblock %}
11 changes: 11 additions & 0 deletions hello_app/templates/hello_there.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='site.css') }}" />
<title>Hello, Flask</title>
</head>
<body>
<span class="message">Hello there, {{ name }}!</span> It's {{ date.strftime("%A, %d %B, %Y at %X") }}.
</body>
</html>
7 changes: 7 additions & 0 deletions hello_app/templates/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "layout.html" %}
{% block title %}
Home
{% endblock %}
{% block content %}
<p>Home page for the Visual Studio Code Flask tutorial.</p>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<html>
<head>
<meta charset="utf-8" />
<title>{{ title }}</title>
<link rel="stylesheet" type="text/css" href="/static/site.css" />
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='site.css') }}" />
</head>

<body>
Expand All @@ -22,4 +22,4 @@
</footer>
</div>
</body>
</html>
</html>
27 changes: 27 additions & 0 deletions hello_app/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from datetime import datetime
from flask import Flask, render_template
from hello_app import app

@app.route('/')
def home():
return render_template("home.html")

@app.route('/about')
def about():
return render_template("about.html")

@app.route('/contact')
def contact():
return render_template("contact.html")

@app.route('/hello/<name>')
def hello_there(name):
return render_template(
"hello_there.html",
name=name,
date=datetime.now()
)

@app.route('/api/data')
def get_data():
return app.send_static_file('data.json')