from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
I am new to Flask. I wrote this basic code and save it in hello.py in my D:\Cat_vs_Dog\scripts folder.
Then in command prompt, I wrote the following commands.
C:\Users\Ketan Ingale>set FLASK_APP=D:\Cat_vs_Dog\scripts\hello.py
C:\Users\Ketan Ingale>flask run
* Serving Flask app "D:\Cat_vs_Dog\scripts\hello.py"
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
Usage: flask run [OPTIONS]
Error: Could not import "D".
I am getting this error. What should I do...?
The flask command is installed by Flask, not your application; it must be told where to find your application in order to use it. The FLASK_APP environment variable is used to specify how to load the application. Unix Bash (Linux, Mac, etc. ): $ export FLASK_APP=hello $ flask run.
Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory. This error happens when flask run command is run before setting The FLASK_APP environment variable.
Command-line: Similarly, the FLASK_ENV variable sets the environment on which we want our flask application to run. For example, if we put FLASK_ENV=development the environment will be switched to development. By default, the environment is set to development.
To run the app outside of the VS Code debugger, use the following steps from a terminal: Set an environment variable for FLASK_APP . On Linux and macOS, use export set FLASK_APP=webapp ; on Windows use set FLASK_APP=webapp . Navigate into the hello_app folder, then launch the program using python -m flask run .
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
app.run()
Remove the directory and just use the name of the file and retry.
You might need to CD
to the directory with your file in it also.
use virtual environment. Follow these steps:
then type
pip install virtualenv
virtualenv env
env\scripts\activate.bat
pip install flask flask-sqlalchemy
python hello.py
Then your web server will be given. copy paste in google chrome.
when you came into the directory using command prompt where you installed virtual environment setup in windows.
Then don't use 'cd' to change the directory to switch into 'virtual environment' folder
Example:
use "env\Scripts\activate" instead "cd env\Scripts\activate".
I hope it will help to others
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With