I have the following in my __init__.py
file.
config = Configurator(settings=settings)
config.include('pyramid_jinja2')
config.include('pathshala.routes.all_routes')
config.add_static_view('static', 'static', cache_max_age=3600)
config.scan()
I have defined all routes in routes.py
which has:
def all_routes(config):
config.add_route('sis_add_student', '/sis/add')
All views are defined in the views.py
file (in the same package) which has:
@view_config(route_name='sis_add_student')
def add_student_view(request):
return Response("Hey there!")
However, when I try opening the path /sis/add
, I get a 404 error. The Debug Toolbar suggests that the correct route has been identified but no view has been associated with that route.
Interestingly, if I move the view declaration to __init__.py
, it works fine.
What am I doing wrong? I feel like my config.scan()
is to blame because it fails to associate a view only when the declaration is in another file but I'm not sure about that and don't know how to fix that.
Looks like you cannot have a package named views
in your project. I had declared views
as a package. Removing that by deleting the __init__.py
from the views directory solved the problem.