Python Revisited 2024: Difference between revisions
Line 53: | Line 53: | ||
requires = ["poetry-core"] | requires = ["poetry-core"] | ||
build-backend = "poetry.core.masonry.api" | build-backend = "poetry.core.masonry.api" | ||
</syntaxhighlight> | |||
==Install Flask== | |||
So we install Flask add run install poetry | |||
<syntaxhighlight lang="toml"> | |||
poetry add Flask | |||
poetry install | |||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 02:14, 27 October 2024
Introduction
A quick revisit to python to maybe improve/refresh my own knowledge.
Project Creation (Poetry)
Guess most folks know about this and knowing IT, some people will hate it, and some will love it. Coming fresh out of NodeJS and React/Nextjs, this seemed a good idea to me. I am starting to feel with AI, that technologies are going to be changing quickly and being able to get going quickly is useful. This looked easy but when I tried it, it was harder. Here goes
Make a Project
poetry new my-project
Make a Fask App
Now lets make a Flask app. We will start by putting the code in src/app
cd my-project
mkdir -p src/app
touch src/app/__init__.py
touch src/app/__main__.py
Now we can make the src/app/__main__.py
from flask import Flask
def main() -> Flask:
app = Flask(__name__)
return app
def run():
app = main()
app.run("localhost", 5000)
if __name__ == "__main__":
Modify the pyproject.toml
The main thing is to change the packages line. I had a bit of trouble getting pylance to find my packages because, maybe, I did not poetry install after this. See below.
[tool.poetry]
name = "my-project"
version = "0.1.0"
description = ""
authors = ["Bill Wiseman <bw@bibble.co.nz>"]
readme = "README.md"
packages = [{ include = "app", from = "src" }]
[tool.poetry.dependencies]
python = "^3.12"
[tool.poetry.group.dev.dependencies]
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Install Flask
So we install Flask add run install poetry
poetry add Flask
poetry install