序文
まず、virtualenv を使用してプロジェクトを分離します。たとえば、投票アプリケーション (投票アプリ) を開発したいとします。
mkdir poll_app cd poll_app virtualenv . source bin/activate
一般的に使用される Python ライブラリ
データベースを必要とするアプリケーションを開発しています。したがって、私は常に flask_script ライブラリと flask_merge ライブラリを使用します。私は Flask の CLI ツールが好きではありません。
Flask スクリプト: https://flask-script.readthedocs.io/en/latest/
Flask 移行: https://flask-merge.readthedocs.io/en/latest/
Django と同様に、manage.py Python ファイルというファイルを作成しました。例:
from MYAPP.data.models import db from MYAPP import app from flask_script import Manager from flask_migrate import Migrate, MigrateCommand db.init_app(app) migrate = Migrate(app, db) manager = Manager(app) manager.add_command('db', MigrateCommand) if __name__ == "__main__": manager.run()
次に、データに対して次の操作を実行できます。
python manage.py db init # --> init migrations python manage.py db migrate # --> migrate models python manage.py db upgrade # --> apply changes python manage.py db --help # --> :)
メイン アプリケーション ファイル
新しいプロジェクトを作成します。ファイルを作成します。ルートフォルダーにapp.pyを追加すると、次のように変更されます。
from MYAPP import app # To do: This place will change later config = { "development": "config.Development" } if __name__ == "__main__": app.config.from_object(config["development"]) app.run()
構成ファイル
また、ルート フォルダーに config.py という構成ファイルを作成しました。
class BaseConfig(object): """ Base config class. This fields will use by production and development server """ ORIGINS = ["*"] # for api calls SECRET_KEY = 'YOUR SECRET KEY' class Development(BaseConfig): """ Development config. We use Debug mode """ PORT = 5000 DEBUG = True TESTING = False ENV = 'dev' # Currently we only have development config. # If you have production, you will need to pass it to here. config = { 'development': 'config.Development' } def configure_app(app): """ App configuration will be here. Parameters ---------- app : Flask app instance """ app.config.from_object(config['development'])
フォルダー構造
ルート ディレクトリにフォルダーを作成し、om_core という名前を付け、Qi api と data に 2 つの新しいフォルダーを作成します。
API ファイルには、アプリケーション ロジックとルーティングが保存されます。たとえば、API に user というフォルダーを作成しました。
他の API レイヤーと同様に、init.py とcontrollers.py という名前の 2 つのファイルをユーザー フォルダーに生成します。 controllers.py (コントローラー ファイル) は次のようになります。
from flask import Blueprint, jsonify, request from MYAPP.data.models import db, User user = Blueprint('user', __name__) @user.route('/', methods=['GET']) def get_users(): return jsonify({ "message": "Hi user :)"}) @user.route('/<int:id>', methods=['GET']) def users(id): return jsonify({ "id": id })
私は常にブループリントを使用します。
データ フォルダーにはいくつかのモデルが保存されます。たとえば、models.py というファイルを作成しました。
from flask_sqlalchemy import SQLAlchemy from MYAPP import app # We didn't pass app instance here. db = SQLAlchemy() class User(db.Model): """ Model for user management """ id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(100), unique=True) password = db.Column(db.String(100)) name = db.Column(db.String(100)) surname = db.Column(db.String(100)) active = db.Column(db.Boolean(), default=True) created_at = db.Column(db.DateTime, default=db.func.now()) updated_at = db.Column(db.DateTime, default=db.func.now()) def __init__(self, email, password, name, surname, active, created_at, updated_at): self.email = email self.password = password self.name = name self.surname = surname self.active = active self.created_at = created_at self.updated_at = updated_at
om_core フォルダーに戻りましょう。 API レイヤーをエンドポイントとして使用するために、init .py というファイルを作成しました。
from flask import Flask from flask_cors import CORS from config import BaseConfig from config import configure_app app = Flask(__name__) from MYAPP.api.user.controllers import user """ Corst settings will be here. We maybe use this endpoint later. """ cors = CORS(app, resources={ r'/api/*': { 'origins': BaseConfig.ORIGINS } }) configure_app(app) app.url_map.strict_slashes = False app.register_blueprint(user, url_prefix='/api/users')
上記のコードでは、Flask-CORS を使用して、さまざまな発信元からのリクエストを許可しています。異なる発信元からのリクエストを許可したくない場合は、これは必要ありません。
プロジェクト全体の構造のスクリーンショット
スクリーンショットは次のとおりです:
推奨チュートリアル: 「Python チュートリアル##」 #「
以上がFlask プロジェクトの構造を理解するの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

Arraysinpython、特にvianumpy、arecrucialinscientificComputing fortheirefficienty andversitility.1)彼らは、fornumericaloperations、data analysis、andmachinelearning.2)numpy'simplementation incensuresfasteroperationsthanpasteroperations.3)arayableminablecickick

Pyenv、Venv、およびAnacondaを使用して、さまざまなPythonバージョンを管理できます。 1)Pyenvを使用して、複数のPythonバージョンを管理します。Pyenvをインストールし、グローバルバージョンとローカルバージョンを設定します。 2)VENVを使用して仮想環境を作成して、プロジェクトの依存関係を分離します。 3)Anacondaを使用して、データサイエンスプロジェクトでPythonバージョンを管理します。 4)システムレベルのタスク用にシステムPythonを保持します。これらのツールと戦略を通じて、Pythonのさまざまなバージョンを効果的に管理して、プロジェクトのスムーズな実行を確保できます。

numpyarrayshaveveraladvantages-averstandardpythonarrays:1)thealmuchfasterduetocベースのインプレンテーション、2)アレモレメモリ効率、特にlargedatasets、および3)それらは、拡散化された、構造化された形成術科療法、

パフォーマンスに対する配列の均一性の影響は二重です。1)均一性により、コンパイラはメモリアクセスを最適化し、パフォーマンスを改善できます。 2)しかし、タイプの多様性を制限し、それが非効率につながる可能性があります。要するに、適切なデータ構造を選択することが重要です。

craftexecutablepythonscripts、次のようになります

numpyarraysarasarebetterfornumeroperations andmulti-dimensionaldata、whilethearraymoduleissuitable forbasic、1)numpyexcelsinperformance and forlargedatasentassandcomplexoperations.2)thearraymuremememory-effictientivearientfa

NumPyArraySareBetterforHeavyNumericalComputing、whilethearrayarayismoreSuitableformemory-constrainedprojectswithsimpledatatypes.1)numpyarraysofferarays andatiledance andpeperancedatasandatassandcomplexoperations.2)thearraymoduleisuleiseightweightandmemememe-ef

ctypesallowsinging andmanipulatingc-stylearraysinpython.1)usectypestointerfacewithclibrariesforperformance.2)createc-stylearraysfornumericalcomputations.3)passarraystocfunctions foreffientientoperations.how、how、becuutiousmorymanagemation、performanceo


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

SecLists
SecLists は、セキュリティ テスターの究極の相棒です。これは、セキュリティ評価中に頻繁に使用されるさまざまな種類のリストを 1 か所にまとめたものです。 SecLists は、セキュリティ テスターが必要とする可能性のあるすべてのリストを便利に提供することで、セキュリティ テストをより効率的かつ生産的にするのに役立ちます。リストの種類には、ユーザー名、パスワード、URL、ファジング ペイロード、機密データ パターン、Web シェルなどが含まれます。テスターはこのリポジトリを新しいテスト マシンにプルするだけで、必要なあらゆる種類のリストにアクセスできるようになります。

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SAP NetWeaver Server Adapter for Eclipse
Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

SublimeText3 Linux 新バージョン
SublimeText3 Linux 最新バージョン

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック









