'werkzeug.routing.BuildError: Could not build url for endpoint 'translate.translate_link'. Did you forget to specify values ['movie_name']?
Movies list is passed to movies.html which contains movie objects, as you can see I can access movie['title] no problem. but when I try to pass movie['title] from the movie_link route to translate route using url_for() in movies.html, it throws this error.
Why does it keep giving me this error? Please note that if I pass in 4 as in
<a href="{{ url_for('translate.translate_link', movie_name=4) }}">
it works just fine. but when I pass movie['title'] it gives me the error. Please also note that I could also pass in movie.overview or even movie.id and it would pass it no problem, but won't pass movie.title and that is driving me crazy
Here is the code:
movies.py
from flask import Blueprint, request, render_template, url_for
from flaskr.db import get_movies
from flaskr.youtubeapi.youtube import youtube_search
bp = Blueprint('movies', __name__, url_prefix='/movies')
bp2 = Blueprint('videos', __name__, url_prefix='/videos')
bp3 = Blueprint('translate', __name__, url_prefix='/translate')
# https://werkzeug.palletsprojects.com/en/2.0.x/routing/
# Rules that end with a slash are “branches”, others are “leaves”.
# If strict_slashes is enabled (the default),
# visiting a branch URL without a trailing slash will redirect to the URL with a slash appended.
@bp.route('/', methods=['GET'], strict_slashes=False)
def movie_list():
movies = get_movies()
return render_template('movies.html', movies=movies)
@bp2.route('/', methods=['GET'], strict_slashes=False)
def movie_link():
name = request.args.get('movie', None)
youtube_link = youtube_search(name)
print(youtube_link)
return render_template('movie-youtube-video-embedded.html', movie_name=youtube_link[0]['snippet']['title'], video_id = youtube_link[0]['id']['videoId'])
@bp3.route('/translate/<movie_name>', methods=['POST', 'GET'], strict_slashes=False)
def translate_link(movie_name):
# return render_template('translate.html', movie = name)
return render_template('translate.html', movie_title = movie_name)
movies.html
<title>Movie Collection</title>
<h1>Movies</h1>
<ul>
{% for movie in movies %}
<li>
<b><a href="{{ url_for('videos.movie_link') }}">{{ movie['title'] }}</a>
<a href="{{ url_for('translate.translate_link', movie_name=movie.title) }}">(translate)</a>: {{ movie['overview'] }}
</b>
</li>
{% endfor %}
</ul>
translate.html
<h1>{{ movie_title }}</h1>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
