Relative import of a apackage in python flask application

狂风中的少年 提交于 2019-12-13 08:27:44

问题


Trying to make the sample flask application more modular,I am new to python and flask trying to build a sample application where , I have planned to maintain the folder structure of the application as shown below

where the description of the package are as fallows

config ---> database configuration details flaskApp 1 model--->which has the mongodb schema 2 viewController----> the endpoint to be accessed

static---> which contains the single html page which i just need to serve (not render it)

The code repo for the same is in github https://github.com/dhanalakshmiZendynamix/python-Flask-relative-module.git

I am facing following problems 1: I am not finding a easy way to access the packages to another packages as in folder structure(ie, models inside viewController where the end points are present)

2:Not sure how to serve the html page inside static folder

Tried reading many source https://exploreflask.com/en/latest/preface.html http://pyvideo.org/pycon-us-2014/writing-restful-web-services-with-flask.html

But still not sure how to get it working

Please help to adopt to the above folder structure and access to the end point really not sure how to go about it

Any suggestion and pointer would help a lot Thank you


回答1:


@dhana lakshmi Check the registered url endpoints in your app. Start Python on the commandline in your project directory and execute the following commands:

>>> import flaskApp 
>>> app = flaskApp.create_app() 
>>> app.url_map 

Please add the output to your question

And I really think you need to read up a bit on python and flask first, here is a list with some great resources on flask https://github.com/humiaozuzu/awesome-flask



来源:https://stackoverflow.com/questions/41280074/relative-import-of-a-apackage-in-python-flask-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!