Search code examples
python-3.xflaskflask-adminvercel

Flask-Admin page not found on production


I have built a Flask app and deployed it to production using Vercel (formerly ZEIT). Everything works except the Flask administration.

It returns URL Not Found when accessing example.com/admin. Some have suggested to move the admin.Admin() initialization block away from the main function. But I don't know what that means. Can somebody help me?

Everything works perfect on my local machine.


Solution

  • I found the answer.

    I fixed it by defining admin interface outside if name == '__main__' .

    This caused the error:

    
    if __name__ == '__main__':
         admin = Admin(application, 'AnyGeeks: Dashboard',index_view=MyIndexView())
         # Add views
         admin.add_view(UserView(Users))
         admin.add_view(ModelView(Tag))
         admin.add_view(PostView(Blog_posts))
         admin.add_view(PostView(Comments))                                                                             
         application.run(debug=True)
    

    This what I did to fix it:

    admin = Admin(application, 'AnyGeeks: Dashboard',index_view=MyIndexView())
    # Add views
    admin.add_view(UserView(Users))
    admin.add_view(ModelView(Tag))
    admin.add_view(PostView(Blog_posts))
    admin.add_view(PostView(Comments))
    
    
    if __name__ == '__main__':                                                                                    
    
       application.run(debug=True)
    

    Now it works perfectly. I have a full website made on flask running on vercel without any issues.