점프 투 플라스크 AttributeError 질문
안녕하세요! 점프 투 플라스크 02-6 답변 등록 기능 만들기 파트에서 답변 등록 버튼을 누르면 자꾸 AttributeError 가 떠서 질문드립니다!
AttributeError: 'Question' object has no attribute 'answer_set'
혹시 제 코드에 문제가 있는 걸까요??
1.init.py
from flask import Flask
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy
import config
db=SQLAlchemy()
migrate=Migrate()
def create_app():
app = Flask(name)
app.config.from_object(config)
#ORM
db.init_app(app)
migrate.init_app(app,db)
from . import models
#블루프린트
from .views import main_views, question_views, answer_views
app.register_blueprint(main_views.bp)
app.register_blueprint(question_views.bp)
app.register_blueprint(answer_views.bp)
return app
- answer_views.py
from datetime import datetime
from flask import Blueprint, url_for, request
from werkzeug.utils import redirect
from pybo import db
from pybo.models import Question, Answer
bp = Blueprint('answer', name, url_prefix='/answer')
@bp.route('/create/
def create(question_id):
question = Question.query.get_or_404(question_id)
content = request.form['content']
answer = Answer(content=content, create_date=datetime.now())
question.answer_set.append(answer)
db.session.commit()
return redirect(url_for('question.detail', question_id=question_id))
랑 님 435
M 2021년 12월 24일 9:05 오후