0

form のコードがあり、フォームを介してデータを保存したい。カスタムフォームは:-

<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>

ビュー.py :-

 @app.route('/contact' ,  methods = ['GET' , 'POST' ])
def contact():
    if request.method == 'POST':
        user = user_email(firstname = request.form['firstname'] , 
            lastname = request.form['lastname'],
            email = request.form['email'],
            subject = request.form['subject'],
            message = request.form['message'])
        user.save()
        return render_template('index.html')
    else:
        return render_template('contact.html')

AttributeError: 'Database' object has no attribute 'model' のエラーがあります。この問題を解決するのを手伝ってください。

4

2 に答える 2

0
<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>
于 2013-11-11T04:02:42.003 に答える