diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..8e52ba28f --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,32 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/python +{ + "name": "Python VS Code Flask Tutorial", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/python:1-3.12-bullseye", + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "pip3 install --user -r requirements.txt", + + // Configure tool-specific properties. + "customizations": { + "vscode": { + "extensions": [ + "ms-python.python", + "ms-python.black-formatter", + "ms-python.vscode-pylance", + "charliermarsh.ruff", + "ms-python.debugpy" + ] + } + } + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..a39d2b053 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +node_modules +npm-debug.log +Dockerfile* +docker-compose* +.dockerignore +.git +.gitignore +README.md +LICENSE +.vscode +__pycache__ +env diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..f33a02cd1 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for more information: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates +# https://containers.dev/guide/dependabot + +version: 2 +updates: + - package-ecosystem: "devcontainers" + directory: "/" + schedule: + interval: weekly diff --git a/.gitignore b/.gitignore index 894a44cc0..45e7bbe6d 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,6 @@ venv.bak/ # mypy .mypy_cache/ + +.vscode/ +settings.json diff --git a/.vscode/launch.json b/.vscode/launch.json index 4e88939b9..9a2737d78 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,121 +5,21 @@ "version": "0.2.0", "configurations": [ { - "name": "Python: runserver.py", - "type": "python", - "request": "launch", - "program": "${workspaceFolder}/runserver.py", - }, - { - "name": "Python: Current File", - "type": "python", - "request": "launch", - "program": "${file}", - "env": { - "FLASK_ENV": "development" - } - }, - { - "name": "Python: Attach", - "type": "python", - "request": "attach", - "localRoot": "${workspaceFolder}", - "remoteRoot": "${workspaceFolder}", - "port": 3000, - "secret": "my_secret", - "host": "localhost" - }, - { - "name": "Python: Terminal (integrated)", - "type": "python", - "request": "launch", - "program": "${file}", - "console": "integratedTerminal" - }, - { - "name": "Python: Terminal (external)", - "type": "python", - "request": "launch", - "program": "${file}", - "console": "externalTerminal" - }, - { - "name": "Python: Django", - "type": "python", - "request": "launch", - "program": "${workspaceFolder}/manage.py", - "args": [ - "runserver", - "--noreload", - "--nothreading" - ], - "debugOptions": [ - "RedirectOutput", - "Django" - ] - }, - { - "name": "Python: Flask (0.11.x or later)", - "type": "python", + "name": "Python Debugger: Flask", + "type": "debugpy", "request": "launch", "module": "flask", "env": { - "FLASK_APP": "HelloFlask/app.py" + "FLASK_APP": "hello_app.webapp", + "FLASK_DEBUG": "1" }, "args": [ "run", "--no-debugger", - "--no-reload" // Remove to auto-reload modified pages - ] - }, - { - "name": "Python: Module", - "type": "python", - "request": "launch", - "module": "module.name" - }, - { - "name": "Python: Pyramid", - "type": "python", - "request": "launch", - "args": [ - "${workspaceFolder}/development.ini" - ], - "debugOptions": [ - "RedirectOutput", - "Pyramid" - ] - }, - { - "name": "Python: Watson", - "type": "python", - "request": "launch", - "program": "${workspaceFolder}/console.py", - "args": [ - "dev", - "runserver", - "--noreload=True" - ] - }, - { - "name": "Python: All debug Options", - "type": "python", - "request": "launch", - "pythonPath": "${config:python.pythonPath}", - "program": "${file}", - "module": "module.name", - "env": { - "VAR1": "1", - "VAR2": "2" - }, - "envFile": "${workspaceFolder}/.env", - "args": [ - "arg1", - "arg2" + "--no-reload" ], - "debugOptions": [ - "RedirectOutput" - ] + "jinja": true, + "justMyCode": true } ] -} \ No newline at end of file +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..4c775f6b9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +# Pull a pre-built alpine docker image with nginx and python3 installed +FROM tiangolo/uwsgi-nginx:python3.8-alpine-2020-12-19 + +# Set the port on which the app runs; make both values the same. +# +# IMPORTANT: When deploying to Azure App Service, go to the App Service on the Azure +# portal, navigate to the Applications Settings blade, and create a setting named +# WEBSITES_PORT with a value that matches the port here (the Azure default is 80). +# You can also create a setting through the App Service Extension in VS Code. +ENV LISTEN_PORT=5000 +EXPOSE 5000 + +# Indicate where uwsgi.ini lives +ENV UWSGI_INI uwsgi.ini + +# Tell nginx where static files live. Typically, developers place static files for +# multiple apps in a shared folder, but for the purposes here we can use the one +# app's folder. Note that when multiple apps share a folder, you should create subfolders +# with the same name as the app underneath "static" so there aren't any collisions +# when all those static files are collected together. +ENV STATIC_URL /hello_app/static + +# Set the folder where uwsgi looks for the app +WORKDIR /hello_app + +# Copy the app contents to the image +COPY . /hello_app + +# If you have additional requirements beyond Flask (which is included in the +# base image), generate a requirements.txt file with pip freeze and uncomment +# the next three lines. +#COPY requirements.txt / +#RUN pip install --no-cache-dir -U pip +#RUN pip install --no-cache-dir -r /requirements.txt diff --git a/HelloFlask/__init__.py b/HelloFlask/__init__.py deleted file mode 100644 index 8d9202853..000000000 --- a/HelloFlask/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -from flask import Flask -app = Flask(__name__) \ No newline at end of file diff --git a/HelloFlask/app.py b/HelloFlask/app.py deleted file mode 100644 index 466f21397..000000000 --- a/HelloFlask/app.py +++ /dev/null @@ -1,5 +0,0 @@ -from HelloFlask import app -from HelloFlask 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') \ No newline at end of file diff --git a/HelloFlask/templates/about.html b/HelloFlask/templates/about.html deleted file mode 100644 index 95b01e1c5..000000000 --- a/HelloFlask/templates/about.html +++ /dev/null @@ -1,4 +0,0 @@ -{% extends "layout.html" %} -{% block content %} -
About page for the Flask tutorial.
-{% endblock %} \ No newline at end of file diff --git a/HelloFlask/templates/contact.html b/HelloFlask/templates/contact.html deleted file mode 100644 index d0a9baebd..000000000 --- a/HelloFlask/templates/contact.html +++ /dev/null @@ -1,4 +0,0 @@ -{% extends "layout.html" %} -{% block content %} -Contact page for the Flask tutorial.
-{% endblock %} \ No newline at end of file diff --git a/HelloFlask/templates/hello_there.html b/HelloFlask/templates/hello_there.html deleted file mode 100644 index 258c06827..000000000 --- a/HelloFlask/templates/hello_there.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - -Home page for the Flask tutorial.
-{% endblock %} \ No newline at end of file diff --git a/HelloFlask/views.py b/HelloFlask/views.py deleted file mode 100644 index 46d1f1e1d..000000000 --- a/HelloFlask/views.py +++ /dev/null @@ -1,31 +0,0 @@ -from flask import Flask -from flask import render_template -from HelloFlask import app - -@app.route('/') -def home(): - return render_template("home.html", title = "Home") - -@app.route('/about') -def about(): - return render_template("about.html", title = "About us") - -@app.route('/contact') -def contact(): - return render_template("contact.html", title = "Contact us") - -@app.route('/hello/About page for the Visual Studio Code Flask tutorial.
+{% endblock %} diff --git a/hello_app/templates/contact.html b/hello_app/templates/contact.html new file mode 100644 index 000000000..3321c9454 --- /dev/null +++ b/hello_app/templates/contact.html @@ -0,0 +1,7 @@ +{% extends "layout.html" %} +{% block title %} +Contact us +{% endblock %} +{% block content %} +Contact page for the Visual Studio Code Flask tutorial.
+{% endblock %} diff --git a/hello_app/templates/hello_there.html b/hello_app/templates/hello_there.html new file mode 100644 index 000000000..de1ef49d1 --- /dev/null +++ b/hello_app/templates/hello_there.html @@ -0,0 +1,16 @@ + + + + + +Home page for the Visual Studio Code Flask tutorial.
+{% endblock %} diff --git a/HelloFlask/templates/layout.html b/hello_app/templates/layout.html similarity index 77% rename from HelloFlask/templates/layout.html rename to hello_app/templates/layout.html index b2de0859a..fd83b92c8 100644 --- a/HelloFlask/templates/layout.html +++ b/hello_app/templates/layout.html @@ -2,8 +2,8 @@ -