Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJacob Murphy
Full Stack JavaScript Techdegree Graduate 32,014 PointsValueError [Solved]
I seem to be encountering an unexplaiable ValueError when I try to load any views with forms after making the post view/form/model. Here's my code
Post View
@app.route('/new_post', methods=('GET', 'POST'))
@login_required
def post():
form = forms.PostForm()
if form.validate_on_submit():
models.Post.create(user=g.user._get_currnet_object(),
content=form.content.data.strip())
flash("Message posted! Thanks!", "success")
return redirect(url_for('index'))
return render_template('post.html', form=form)
Post Form
@app.route('/new_post', methods=('GET', 'POST'))
@login_required
def post():
form = forms.PostForm()
if form.validate_on_submit():
models.Post.create(user=g.user._get_currnet_object(),
content=form.content.data.strip())
flash("Message posted! Thanks!", "success")
return redirect(url_for('index'))
return render_template('post.html', form=form)
Post Model
class Post(Model):
timestamp = DateTimeField(default=datetime.datetime.now)
user = ForeignKeyField(
rel_model = User,
related_name = 'posts' )
content = TextField()
class Meta:
database = DATABASE
order_by = ('-timestamp',)
[MOD: Added python to markdown formatting -cf]
Jacob Murphy
Full Stack JavaScript Techdegree Graduate 32,014 PointsThe Value error I'm getting displays the Message "builtins.ValueError
ValueError: too many values to unpack (expected 2)"
with two lines of code from my actual files quoted at the bottom:
File "/home/treehouse/workspace/templates/register.html", line 2, in <module>
{% from 'macros.html' import render_field %}
File "/home/treehouse/workspace/templates/layout.html", line 55, in <module>
{% for category, message in messages %}
Everything seems to work until I try to access /new_post
, then every page with a form breaks.
Jacob Murphy
Full Stack JavaScript Techdegree Graduate 32,014 PointsI fixed it! It was indeed in layouts.html
on line 53 it should have been {% with messages = get_flashed_messages(with_categories=True) %}
but I had True in all caps
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsCan you add the actual
ValueError
you're seeing?