Specifying the module loading destination with GAE python

Create and import (import) library storage when using existing modules such as Flask on GAE in a natural way

When you have created main.py and lib folders in the same hierarchy as app.yaml and want to import various libraries from main.py

root_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(root_dir, 'lib'))

Is OK if you write it just before import

sample

#!coding:utf8
import os
import sys
from datetime import date
from google.appengine.ext import ndb
from google.appengine.ext.webapp.util import run_wsgi_app

import csv
import json
import urllib
import datetime
from random import randint

root_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(root_dir, 'lib'))

import jinja2
from flask import Flask
from flask import request
from flask import jsonify
from flask import redirect
from flask import render_template

from models import MyModel

Recommended Posts

Specifying the module loading destination with GAE python
Download the file by specifying the download destination with Python & Selemiun & Chrome (Windows version)
Examine Python script bottlenecks with the cProfile module
About the Python module venv
Call the API with python3.
Why can I use the module by importing with python?
Minimum knowledge to get started with the Python logging module
Extract the xz file with python
Specifying the date with the Twitter API
Get the weather with Python requests
Get the weather with Python requests 2
Find the Levenshtein Distance with python
Hit the Etherpad-lite API with Python
Install the Python plugin with Netbeans 8.0.2
I liked the tweet with python. ..
Master the type with Python [Python 3.9 compatible]
Try using the Python Cmd module
Master the weakref module in Python
The story of making a module that skips mail with python
Create a compatibility judgment program with the random module of python.
Get the link destination URL by specifying a text sentence with Python scraping (Beautiful Soup) + XPath
Make the Python console covered with UNKO
[Python] Set the graph range with matplotlib
Behind the flyer: Using Docker with Python
Pass the path of the imported python module
Play around with the pythonista3 ui module
Check the existence of the file with python
[Python] Get the variable name with str
[Python] Round up with just the operator
Display Python 3 in the browser with MAMP
Search the maze with the python A * algorithm
Let's read the RINEX file with Python ①
Install by specifying the version with pip
Download files on the web with Python
[Python] Import the module one level higher
Check the path of the Python imported module
I get a Python No module named'encodings' error with the aws command
Install the python module with pip on a server without root privileges
Create a record with attachments in KINTONE using the Python requests module
Learn the design pattern "Singleton" with Python
[Python] Automatically operate the browser with Selenium
[Python] How to deal with module errors
Install the Python module in any directory
Learn the design pattern "Facade" with Python
The road to compiling to Python 3 with Thrift
Error when installing a module with Python pip
I tried "smoothing" the image with Python + OpenCV
[Python] Get the files in a folder with Python
Load the network modeled with Rhinoceros in Python ③
Prepare the execution environment of Python3 with Docker
2016 The University of Tokyo Mathematics Solved with Python
I tried "differentiating" the image with Python + OpenCV
[Python] Let's execute the module regularly using schedule
Find the mood value with python (Rike Koi)
[Note] Export the html of the site with python.
The easiest way to synthesize speech with python
Try to solve the man-machine chart with Python
[Automation] Extract the table in PDF with Python
Calculate the total number of combinations with python
Specify the Python executable to use with virtualenv
Specifying the range of ruby and python arrays