Reputation: 53
here is the way i create a user:
if form.validate():
flash('Thanks for registration ' + name)
Session = sessionmaker(bind=engine)
session = Session()
user = User(name,password,coins)
session.add(user)
session.commit()
else:
flash('Error: All the form fields are required. ')
Traceback says that NameError: global name 'User' is not defined, and points to this:
user = User(name,password,coins)
I use SQLite3, and the database table is called "User", so... i don't know what the problem is!
My imports are:
import os
import sys
import pprint
from flask import Markup
from flask import redirect, url_for, session
from flask import redirect, render_template, request, session, abort
from sqlalchemy.orm import sessionmaker
from tabledef import *
from flask import Flask, render_template, flash, request
from wtforms import Form, TextField, TextAreaField, validators,
StringField, SubmitField
import sqlite3 as lite
sorry thats its a bit messy...
Upvotes: 2
Views: 877
Reputation: 53
Ok so i figured it out.. Thanks guys! I needed to import the python script where i define User(). Rookie mistake sry...
Upvotes: 1
Reputation: 527
I think the problem is since you haven't imported User. Hope it works.
from models import User
Upvotes: 2