@AliminVerckon

Почему не создается запрос в бд?

@app.route('/docs_add', methods=['POST', "GET"])
@login_required
def DAdd():
    forms = AddDocsForm(request.form)
    if forms.validate_on_submit():
        doc = Docs(name_doc=forms.name.data, files=forms.path.data, format_id=forms.format.data)
        db.session.add(doc)
        db.session.commit()
        flash("Success: Записано")
    return render_template('/DAdd.html', title="Добавление документов")

<h1>Добавление документов</h1>
    <form enctype="multipart/form-data" action="/docs_add", method="post">
        <div class="row">
            <div class="col-lg-5">
                <h4>Имя</h4>
                <input class="form-control form-control-lg" type="text", name="name" id="name">
            </div>
            <div class="col-lg-5">
                <h4>Файл</h4>
                <input class="form-control form-control-lg" type="text", name="path" id="path">
            </div>
            <div class="col-lg-2">
                <h4>Формат</h4>
                <input class="form-control form-control-lg" type="number" name="format" id="format">
            </div>
        </div>
        <input class="form-control form-control-lg" type="submit" id="submit" name="submit" value="Добавить">
    </form>
    <div class="container good">
        {% with messages = get_flashed_messages() %}
            {% if messages %}
                <ul class=flashes>
                    {% for message in messages %}
                        <li>{{ message }}</li>
                    {% endfor %}
                </ul>
            {% endif %}
        {% endwith %}
    </div>

class AddDocsForm(FlaskForm):
    name = StringField('name', validators=[DataRequired()])
    path = StringField('path', validators=[DataRequired()])
    format = IntegerField('format', validators=[DataRequired()])
    submit = SubmitField('submit')

class Format(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    format_file = db.Column(db.String, index=True)
    id_format = db.Column(db.Integer, index=True, unique=True)
    docs_id = db.relationship('Docs', backref="doc_id", lazy='dynamic')

class Docs(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name_doc = db.Column(db.String, nullable=True)
    files = db.Column(db.String, nullable=True)
    format_id = db.Column(db.Integer, db.ForeignKey('format.id'))
  • Вопрос задан
  • 20 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы