我目前正在构建一个菜谱应用程序,用户可以创建自己的菜谱,这些菜谱存储在数据库中。用户可以在文本区域中输入配方成分和说明。你知道吗
placeholder="Type hier al de ingredienten. Houd het leesbaar voor jezelf en anderen door de opmaak netjes te houden">
placeholder="Schrijf hier de instructies om het gerecht te maken">
Wil je een foto toevoegen?
Voeg het recept toe!
这将在下面的模型中结束class Recipe(Base):
__tablename__ = "recipes"
recipe_id = Column(Integer, primary_key=True, autoincrement=True, nullable=False, unique=True)
recipe_name = Column(String(100), nullable=False)
recipe_ingredients = Column(Text)
recipe_instructions = Column(Text)
recipe_image_url = Column(String)
user_id = Column(Integer, ForeignKey("users.user_id"))
author = relationship("User", backref=backref('recipe', uselist=False))
def __init__(self, recipe_name, recipe_ingredients, recipe_instructions, recipe_image_url, user_id):
self.recipe_name = recipe_name
self.recipe_ingredients = recipe_ingredients
self.recipe_instructions = recipe_instructions
self.recipe_image_url = recipe_image_url
self.user_id = user_id
到目前为止还不错。用户填写表单,将所有配料和说明放在新行上,然后将配方保存在数据库中。
只有当我从数据库中读取配方以向用户显示配方时,格式就消失了,配料和说明显示为一个长字符串。你知道吗@routes.route("/recipe", methods=["GET", "POST"])
def recipe():
if request.method == "POST":
selected_recipe = DAO.fetch_recipe(request.form.get("selected_recipe"))
author = DAO.fetch_author(selected_recipe.user_id)
return render_template("recept.html", selected_recipe=selected_recipe, author=author)
else:
return redirect(url_for("/"))
{% block main %}
Recept Pagina
{{ selected_recipe.recipe_name }}
{{ selected_recipe.recipe_ingredients }}
{{ selected_recipe.recipe_instructions }}
{% endblock %}
我用这种方法绞尽脑汁的时间比我应该用的时间长,任何帮助都会非常感激。你知道吗