News website using Flask and news API - Hello World : Part 3
Hello guys,
I think you followed previous steps so you won't get any error.
Day by Day corona cases is increasing and may rise more so just be safe.
I am using VSCode
This is the free and best software to use for python.
Install some extension Flask Snippets, bootstrap.
open newsapp folder in VSCode
Create app.py file
Structure
And code as below
I think you followed previous steps so you won't get any error.
Day by Day corona cases is increasing and may rise more so just be safe.
I am using VSCode
This is the free and best software to use for python.
Install some extension Flask Snippets, bootstrap.
open newsapp folder in VSCode
Create app.py file
Structure
And code as below
- First we imported the
Flask
class. An instance of this class will be our WSGI application. - Next we create an instance of this class. The first argument is the name of the application’s module or package. If you are using a single module (as in this example), you should use
__name__
because depending on if it’s started as application or imported as module the name will be different ('__main__'
versus the actual import name). This is needed so that Flask knows where to look for templates, static files, and so on. For more information have a look at theFlask
documentation. - We then use the
route()
decorator to tell Flask what URL should trigger our function. - The function is given a name which is also used to generate URLs for that particular function, and returns the message we want to display in the user’s browser.
How to run this app?
(env) E:\flask\newsapp>python app.py
or
(env) E:\flask\newsapp>py app.py
Output:
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
As we see above this is a production environment and debug is not allowed.
Whenever we deploy any application on server we must have to stop debugging option.
If we change
and this app
Output :
(env) E:\flask\newsapp>py app.py
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Restarting with stat
* Debugger is active!
* Debugger PIN: 100-183-505
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
That's it for today!!
This is our first simple flask application.
❤❤Quarantine python group link ❤❤
8805271377 WhatsApp
Follow here ❤
@mr._mephisto_ Instagram
There will be no restrictions just feel free to learn.
Share and take one more step to share knowledge with others.
Believe in yourself 🤟 you are awesome.
Be safe, Be happy😁
Take care of yourself and your family
Of course, watch movies and series🤟😉
And follow the guidelines of the government
Comments
Post a Comment