mbr / flask-bootstrap

Ready-to-use Twitter-bootstrap for use in Flask.
http://pypi.python.org/pypi/Flask-Bootstrap
Other
1.57k stars 724 forks source link

Key Error for paths with arguments #170

Open theflashpack opened 6 years ago

theflashpack commented 6 years ago

Hopefully this is the right place - really struggling to get to the bottom of this. I have the following versions:

Flask (0.12.2)
Flask-Bootstrap (3.3.7.1)
flask-nav (0.6)

I have a blueprint:

mod_profiles = Blueprint('mod_profiles', __name__)

@mod_profiles.route('/profile/', defaults={'profile_id': ''}, methods=['GET', 'POST'])
@mod_profiles.route('/profile/<profile_id>', methods=['GET', 'POST'])
def profile_page(profile_id):
    app.logger.debug(profile_id)
    return render_template('mod_profiles/index.html')

A nav bar:

@nav.navigation()
def top_level_nav():
    return Navbar(
        Markup(
            '<a href="/"><img src="' +
            url_for("static", filename="img/freezus-logo.svg") +
            '" width="30"></a>'
        ),
        View('Profile', 'mod_profiles.profile_page'),
        View('Cameras', 'mod_cameras.cameras_page'),
        View('Calibrate', 'mod_calibrate.calibrate_page'),
  )

but whenever I go to the profile page I get an error (traceback trimmed down to last few lines from nav.top_level_nav.render()) (cameras and calibration page work fine - they don't have any arguments)

File "/Users/flashpack/code/freezus/freezusserver/freezusserver/templates/base.html", line 32, in block "navbar"
    {{nav.top_level_nav.render()}}
  File "/Users/flashpack/.virtualenvs/freezus/lib/python3.6/site-packages/flask_nav/elements.py", line 24, in render
    self))
  File "/Users/flashpack/.virtualenvs/freezus/lib/python3.6/site-packages/visitor/__init__.py", line 48, in visit
    return meth(node)
  File "/Users/flashpack/.virtualenvs/freezus/lib/python3.6/site-packages/flask_bootstrap/nav.py", line 53, in visit_Navbar
    bar_list.add(self.visit(item))
  File "/Users/flashpack/.virtualenvs/freezus/lib/python3.6/site-packages/visitor/__init__.py", line 48, in visit
    return meth(node)
  File "/Users/flashpack/.virtualenvs/freezus/lib/python3.6/site-packages/flask_bootstrap/nav.py", line 99, in visit_View
    if node.active:
  File "/Users/flashpack/.virtualenvs/freezus/lib/python3.6/site-packages/flask_nav/elements.py", line 89, in active
    append_unknown=not self.ignore_query)
  File "/Users/flashpack/.virtualenvs/freezus/lib/python3.6/site-packages/werkzeug/routing.py", line 806, in build
    add(self._converters[data].to_url(values[data]))
KeyError: 'profile_id'

Any pointers? Has worked with previous versions, so I'm possibly missing something obvious...

mbr commented 6 years ago

Hmm, wild guess would be some sort of issue with the default_parameters setup.

Has worked with previous versions

Could you tell me which versions those were?

theflashpack commented 6 years ago

I commented that out to just have

@mod_profiles.route('/profile/<profile_id>', methods=['GET', 'POST'])
def profile_page(profile_id):
    app.logger.debug(profile_id)
    return render_template('mod_profiles/index.html')

same result.

Was working with 'Flask==0.10.1', 'Flask-Bootstrap==3.3.5.7', 'Flask-Nav==0.5', on python 2.7