Flask run not working when running it on powershell - python

Error: Could not locate a Flask application. Use the 'flask --app' option, 'FLASK_APP' environment variable, or a 'wsgi.py' or 'app.py' file in the current directory.
I am trying to run flask as I am just starting to learn about back end but I cant seem to solve this problem. Please help

First check you working directory, you should be in the same directory that your flask app is, you can use cd c:/path/to/app to change directory or hold shift and right click in that directory and choose open powershell here.
Also it is better to rename your app to app.py, flask will run it by default, otherwise you should set FLASK_APP variable with $env:FLASK_APP = "app_name.py"

Related

Running move and delete commands on Heroku CLI

I've recently deployed an application to Heroku. Due to the constraints of the file system I'm looking to replace two css files within a Flask Package upon the application starting.
My main goal is to take a file from the app directory (the file is part of the git repo) and use it to replace a python package file located in the site packages directory.
I've tried to run the following from the Heroku CLI but nothing seems to happen.
heroku run mv ./bootstrap.css ./.heroku/python/lib/python3.6/site-packages/flask_bootstrap/static/css/bootstrap.css
I've also tried to remove the files from the site packages directory using RM but again nothing happens.
Could you please let me know if standard unix commands work on Heroku?
Fork and edit flask_bootstrap and add that to requirements.txt file like this.
Heroku using ephemeral filesystem. Whatever change you made to your filesystem only last until the dyno is restarted.
So my opinion is to change the file in your local repo and push to heroku again.
Source : https://help.heroku.com/K1PPS2WM/why-are-my-file-uploads-missing-deleted

How to run python apps on a shared host with no bash or console command prompt privileges?

I want to run a python app called Flask on shared hosting but I don't have access to bash or command prompt or ssh but I am provided with:
Well, that's okay! Let me explain what I see in case the image cant be seen
Configuration files: A button that says RUN PIP INSTALL
A text field that says: Enter another file and press enter
Environment variables and an ADD button.
I know how to do this on my local machine
pip install flask
But how do I do it on the shared hosting?
I have a virtual environment that is just a folder but I can't access it since no ssh but it looks like
Well, I have figured it out and I want to share my experience here.
step 1.
on the cpanel, scroll and find python under software and click it.
step 2.
creat application
select python version
application root is where you will upload your data
Application startup file is and should be: init.py
Application Entry point will be: application
Passenger log file: blog.log
click create
step 3
open passenger_wsgi.py and type:
import os
import sys
from init import app as application
sys.path.insert(0, os.path.dirname(file))
save
step 4
creat you app on your lacal machine and pip freeze all requirement
copy the requirement.txt files and upload it to your application root folder and
click python again from your cpanel software and click edit your application
on Configuration files, type your requirement .txt and click add
then keep building your app on your lacal machine and upload your files they will run
This video was the best tutorial I could find on how to properly configure a shared host (cPanel/Phusion Passenger) to work with Flask.
The only other thing I do to avoid the importlib nagging warning
DeprecationWarning: the imp module is deprecated in favour of
importlib; see the module's documentation for alternative uses
is to change the default passenger_wsgi.py contents to
from app import app as application
Beware that this file might be rewritten when changing the application through the cPanel page.

dev_appserver.py doesn't run the app engine, instead it asks how do I want to open .py files for windows 10

I am currently running a tutorial for python on google app engine using the python docs samples repository. When I try to run dev_appserver.py in the hello_world folder, it doesn't open the app engine locally, but instead asks me how I want to display .py files, which if I select an application, will open it as a python text file instead.
Thanks
You're probably best off using the command line to start up the local development server.
From the Start menu, you can search for cmd to open the command prompt. You might need to right click it and choose "Run as administrator."
Change directories to where your application's app.yaml file is located. For example:
cd C:\Users\<myname>\<myfolder_with_app.yaml>\
Run the dev_appserver.py against the current directory (indicated by the dot):
python dev_appserver.py .
If you get a command not found error, then you need to install Python. If you get a could not find the dev_appserver.py file then your PATH environment variable doesn't have the SDK path in it. See Using the Local Development Server for more information including troubleshooting.

use dev_appserver.py for specific file in a directory

In order to start Google app engine through the cmd i use: dev_appserver.py --port=8080, but i can't figure how does it pick a file to run from the current directory.
My question is, is there an argument specifying a file to run in the server from all possible files in the directory?
dev_appserver doesn't "run a file" at all. It launches the GAE dev environment, and routes requests using the paths defined in app.yaml just like the production version.
If you need to route your requests to a specific Python file, you should define that in app.yaml.

Run App Engine development server with modules in PyCharm

Since the latest release of the Google App Engine Python SDK, it's possible to use modules. I have a Python application with a default module and another module. To start the module in the development server, the development server has to be run like this:
dev_appserver.py app.yaml othermodule.yaml
When I add app.yaml othermodule.yaml to "Additional options" in the Run/Debug configuration of PyCharm and then run the development server, I get the following error message:
google.appengine.tools.devappserver2.errors.InvalidAppConfigError: "."
is a directory and a yaml configuration file is required
This is because PyCharm adds a dot at the end of the command to run the development server, like this:
dev_appserver.py app.yaml othermodule.yaml .
Is it possible to remove the dot, or do I have to wait until this is fixed in PyCharm? Before there were modules, there was no need for this.
You can go around this for the time being by just creating a new Run Configuration.
Chose Python configuration, then fill like this:
script: /path/to/your/dev_appserver.py
script parameters: dispatch.yaml module1.yaml module2.yaml
working directory: /path/to/your/appengine/project
It works just fine like this for me. The dispatcher is launching properly and I've got all the logs like before in PyCharm.

Categories