Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key Error for paths with arguments #170

Open
theflashpack opened this issue Oct 12, 2017 · 2 comments
Open

Key Error for paths with arguments #170

theflashpack opened this issue Oct 12, 2017 · 2 comments

Comments

@theflashpack
Copy link

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
Copy link
Owner

mbr commented Oct 15, 2017

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
Copy link
Author

theflashpack commented Oct 16, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant