Search code examples
pythonpython-3.xnavigationflask-restful

python-flask Nomodule named 'flask_nav'


Actually I am learning python flask Navigation, I installed all the necessary packages successfully, these are some of the packages,

app$ venv/bin/easy_install  flask-restful
app$ venv/bin/easy_install  Flask-bootstrap
app$ venv/bin/easy_install  Flask-Navigation

but when I am tring to import

   from flask_nav import Nav
         or
   from flask_nav.elements import Navbar, View

getting error,

>>>from flask_nav import register_renderer
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'flask_nav'

I am using ubuntu-14.02 and Python 3.4.3. How do i fix this error, any solution.


Solution

  • According to Flask-Navigation documentation, you should be importing Navigation and not Nav

    from flask import Flask
    from flask.ext.navigation import Navigation
    
    app = Flask(__name__)
    nav = Navigation(app)
    

    You might be confusing Flask-Navigation with Flask-Nav which is installed under the package name flask-nav.

    From the documentation, here are some differences between Flask-Nav to Flask-Navigation:

    Flask-Nav owes a some good core ideas to Flask-Navigation, which is about a year older and the first place the author looked before deciding to write Flask-Nav. In defense of the reimplementation. Here are some key differences:

    • Flask-Navigation rolls all element types into a single Item class, which serves as label, view and link element. This makes it a little hard to extend.
    • The HTML generation in Flask-Navigation is done inside the package itself, while Flask-Nav uses a more complete, external solution.
    • Navigational structure creation and rendering are separate in Flask-Nav (see Renderer). This allows for more than one way of rendering the same navbar, allowing other packages (such as Flask-Bootstrap) to supply renderers as well.
    • Some technical choices were deemed a little strange and have been avoided (BoundTypeProperty)
    • While Flask-Navigation uses signals and hooks to regenerate navigation bars on every request, Flask-Nav achieves dynamic behaviour by lazily instantiating naviigation bars when they are needed and at the last possible moment.