In your view new.html file you are referencing a post record. I suppose you should be displaying the form. [[=form]] Just keep experimenting and note that if a valid record id from db.post in not found then it would evaluate as None. This means that, for example, post.title would then give an error in your views.
On Thursday, 10 December 2020 at 23:17:31 UTC [email protected] wrote: > While redoing my own damn tutorial I'm running into a problem that has to > be painfully obvious to anyone on the world but me. I get the message > "NameError: name 'post' is not defined" when I try to do a /new in the > following conditions. What idiocy am I committing here? > > *file models.py:* > from .common import db, Field > from pydal.validators import * > > db.define_table('post', > Field('title','string',notnull=True), > Field('url', 'text',IS_URL()), > Field('body','string')) > > db.commit() > > *new.html:* > [[extend 'layout.html']] > <h1>[[=post.title]]</h1> > <p>[[=post.body]]</p> > [[=A('Home', _href=URL('index'))]] > > *post.html:* > [[extend 'layout.html']] > <h1>[[=post.title]]</h1> > <p>[[=post.body]]</p> > [[=A('Home', _href=URL('index'))]] > > *In controllers.py:* > @action("post/<id>") > @action.uses('post.html') > def post(id): > post=db.post(id) > form=Form(db.post,post) > return dict(post=post,form=form) > > @action('new',method=['GET','POST']) > @action.uses(auth,flash,session,'new.html') > def new(): > form=Form(db.post) > if form.accepted: > redirect(URL('index')) > elif form.errors: > flash.set('You\'ll need either a URL or a comment', class_="error") > return dict(form=form) > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/1a681b51-1644-4dca-9098-23c568f49354n%40googlegroups.com.

