Directory Structure:
__init__
:
from flask import flask
app = Flask(__name__)
if __name__ == '__main__'
app.run()
Views:
from app import app
@app.route('/')
def hello_world():
return 'Hello World!'
I hope someone can explain what I am doing wrong here -
I guess I'm not understanding how to properly import app
. This results in a 404. However when views is moved back to __init__
everything works properly.
You'll get 404 errors if you've deleted or removed pages from your site recently without redirecting their URLs. 404 errors can also occur if you've relaunched or transferred your domain and failed to redirect all your old URLs to the new site. Sometimes 404 errors can be the result of changing a page's URL.
You need to explicitly import your views
module in your __init__
:
from flask import flask
app = Flask(__name__)
from . import views
Without importing the module, the view registrations are never made.
Do keep the script portion outside of your package. Add a separate file in Final_app
(so outside the app
directory) that runs your development server; say run.py
:
def main():
from app import app
app.run()
if __name__ == '__main__'
main()
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