2

I am currently working on a flask_app. This is my project structure

├── pypi_org
│   ├── __pycache__
│   │   └── app.cpython-37.pyc
│   ├── app.py
│   ├── services
│   │   └── package_services.py
│   ├── static
│   │   ├── css
│   │   │   └── site.css
│   │   ├── html
│   │   └── js
│   ├── templates
│   │   ├── home
│   │   │   ├── about.html
│   │   │   └── index.html
│   │   ├── packages
│   │   │   └── details.html
│   │   └── shared
│   │       └── _layout.html
│   ├── tests
│   ├── viewmodels
│   └── views
│       ├── home_views.py
│       └── package_views.py
├── requirements-dev.txt
└── requirements.text

I have defined the blueprint in home_views.py

from flask import render_template
from flask import Blueprint
from pypi_org.services import package_services

blueprint = Blueprint('home', __name__, template_folder='templates')


@blueprint.route('/')
def index():
    test_packages = package_services.get_latest_packages()
    return render_template('home/index.html', packages=test_packages)


@blueprint.route('/about')
def about():
    return render_template('home/about.html')

Code for app.py is given below

from flask import Flask
from pypi_org.views import home_views, package_views

app = Flask(__name__)


def main():
    register_blueprints()
    app.run(debug=True)


def register_blueprints():
    app.register_blueprint(home_views.blueprint)
    app.register_blueprint(package_views.blueprint)


if __name__ == '__main__':
    main()

When I run the app.py I get the 404 error. I'm not sure what I am doing wrong. Everything looks right.

Can someone take a look?

sampippin
  • 103
  • 2
  • 10
  • What happens if you comment out `app.register_blueprint(package_views.blueprint)`? – Dave W. Smith Jul 04 '19 at 21:43
  • Try putting your `html` files inside another `templates` folder e.g. `templates\home\templates\index.html`, see http://flask.pocoo.org/docs/1.0/blueprints/#templates – PGHE Jul 04 '19 at 22:21
  • I am using pycharm. If the cwd is `/Applications/PyCharm.app/Contents/bin` , then it works without any issues. not sure why this is the case – sampippin Jul 04 '19 at 22:42
  • @sampippin Did you finally figure out what it is? I have the same issue – Bogdan Mind Dec 07 '21 at 14:05

0 Answers0