feat: 初始版本,圆角主题与首次管理员引导
This commit is contained in:
17
app/blueprints/comments.py
Normal file
17
app/blueprints/comments.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from flask import Blueprint, request, redirect, url_for
|
||||
from flask_login import login_required, current_user
|
||||
from ..extensions import db
|
||||
from ..models import Comment, Post
|
||||
|
||||
bp = Blueprint("comments", __name__, url_prefix="/comments")
|
||||
|
||||
@bp.route("/create/<int:post_id>", methods=["POST"])
|
||||
@login_required
|
||||
def create(post_id):
|
||||
post = Post.query.get_or_404(post_id)
|
||||
body = request.form.get("body")
|
||||
if body:
|
||||
c = Comment(post_id=post.id, user_id=current_user.id, body=body)
|
||||
db.session.add(c)
|
||||
db.session.commit()
|
||||
return redirect(url_for("posts.detail", post_id=post.id))
|
||||
Reference in New Issue
Block a user