Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 把表格保存在烧瓶里?_Python_Flask_Peewee - Fatal编程技术网

Python 把表格保存在烧瓶里?

Python 把表格保存在烧瓶里?,python,flask,peewee,Python,Flask,Peewee,我有表单的代码,我想通过表单保存数据。 自定义表格为:- <form class="well span12 c1" name="contacts" method="POST"> <label>First Name</label> <input type="text" placeholder="Your First Name" class="span12" required name="firstname" >

我有表单的代码,我想通过表单保存数据。 自定义表格为:-

<form class="well span12 c1" name="contacts" method="POST">
<label>First Name</label>
            <input type="text" placeholder="Your First Name" class="span12" required  name="firstname" >
            <label>Last Name</label>
            <input type="text" placeholder="Your Last Name" class="span12" required   name="lastname" >
            <label>Email Address</label>
            <input type="text" placeholder="Your email address" class="span12" required  name="email" >
            <label>Subject</label>
            <select class="span12" name="subject" id="subject" required >
                <option value="na" selected="">Choose One:</option>
                <option value="service">General Customer Service</option>
                <option value="suggestions">Suggestions</option>
                <option value="product">Product Support</option>
            </select>


            <label>Message</label>
            <textarea rows="8" class="input-xlarge span12" id="message" name="message" required ></textarea>

        <button class="btn btn-primary pull-right" style="border-radius:0px;" type="submit">Send</button>

</form>

AttributeError出错:“数据库”对象没有属性“模型”。请帮助我解决此问题。

您是否已设置数据库并连接到该数据库?它应该是这样的:

# define a database connection
database = peewee.SqliteDatabase('my.db')

class BaseModel(peewee.Model):
    class Meta:
        # this is likely the missing part of your model
        # you need to tell the model which database connection to use.
        database = database

class User(BaseModel):
    first_name = peewee.CharField()
    last_name = peewee.CharField()
    email = peewee.CharField()
    subject = peewee.CharField()
    message = peewee.CharField()

名字
姓
电子邮件地址
主题
选择一个:
一般客户服务
建议
产品支持
消息
发送

仅错误消息是有帮助的,但还不够。编辑问题并发布完整的回溯。它应该包括行号。查看回溯中与代码相关的行,以帮助确定问题。
# define a database connection
database = peewee.SqliteDatabase('my.db')

class BaseModel(peewee.Model):
    class Meta:
        # this is likely the missing part of your model
        # you need to tell the model which database connection to use.
        database = database

class User(BaseModel):
    first_name = peewee.CharField()
    last_name = peewee.CharField()
    email = peewee.CharField()
    subject = peewee.CharField()
    message = peewee.CharField()
<form class="well span12 c1" name="contacts" method="POST" action="{{ url_for('contact') }}"> 
  <div class="row-fluid">
        <div class="span6">
            <label>First Name</label>
            <input type="text" placeholder="Your First Name" class="span12" required  name="firstname" >
            <label>Last Name</label>
            <input type="text" placeholder="Your Last Name" class="span12" required   name="lastname" >
            <label>Email Address</label>
            <input type="text" placeholder="Your email address" class="span12" required  name="email" >
            <label>Subject</label>
            <select class="span12" name="subject" id="subject" required >
                <option value="na" selected="">Choose One:</option>
                <option value="service">General Customer Service</option>
                <option value="suggestions">Suggestions</option>
                <option value="product">Product Support</option>
            </select>
        </div>
        <div class="span6">
            <label>Message</label>
            <textarea rows="8" class="input-xlarge span12" id="message" name="message" required ></textarea>
        </div>

        <button class="btn btn-primary pull-right" style="border-radius:0px;" type="submit">Send</button>
    </div>
</form>