我有个Flask应用程序,它有一个名为projects
的程序包。我尝试呈现模板时遇到问题-它不会显示在HTML页面中。查询的数据库表名为“项目”。
这是routes.py
文件的内容:
from flask import render_template, redirect, request, url_for, flash
from flask_login import (
current_user,
login_required,
login_user,
logout_user
)
from app import db, login_manager
from app.projects import blueprint
from app.projects.models import Project
@blueprint.route("/projects_list")
@login_required
def projects_list():
projects = Project.query.all()
return render_template('projects_list.html', projects=projects)
projects_list.html:
{% extends "base_site.html" %}
{% block title %} Projects {% endblock title %}
{% block stylesheets %}
{{ super() }}
{% endblock stylesheets %}
{% block content %}
<div class="right_col">
<div>Project Name:
{% for project in projects %}
{{ project.project_name }}
{% endfor %}
</div>
</div>
{% endblock content %}
models.py:
from datetime import datetime
#from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from flask import current_app
from flask_login import current_user, login_required
from app import db, login_manager
from flask_login import UserMixin
class Project(db.Model):
id = db.Column(db.Integer, primary_key=True)
project_name = db.Column(db.String(100), nullable=False)
date_created = db.Column(db.DateTime, nullable=True, default=datetime.utcnow)
keywords = db.Column(db.Text, nullable=False)
def __repr__(self):
return f"Project('{self.project_name}')"