• 카테고리

    질문 & 답변
  • 세부 분야

    풀스택

  • 해결 여부

    미해결

에러문의

22.09.01 22:26 작성 조회수 693

1

6분 44초까지 코드 완성했는데 이런 에러가 뜨네요(빌드에러)

이전까지는 다 잘 됐습니다.

2022-09-01 22 27 17.png

제 코드 입니다.

@blueprint.route("/comment_write", methods=["POST"])
@login_required
def comment_write():
    if request.method == "POST":
        name = session.get("name")
        writer_id = session.get("id")
        root_idx = request.form.get("rood_idx")
        comment = request.form.get("comment")
        current_utc_time = round(datetime.utcnow().timestamp() * 1000)

        c_comment = mongo.db.comment

        post = {
            "root_idx": str(root_idx),
            "writer_id": writer_id,
            "name": name,
            "comment": comment,
            "pubdate": current_utc_time
        }
        
        c_comment.insert_one(post)
        return redirect(url_for("board.board_view", idx=root_idx))


아래는 뷰 html 코드입니다.


<form id="commentForm" name="commentForm" action="{{url_for('board.comment_write')}}" method="POST">
    <input type="hidden" name="csrf_token" value="{{csrf_token()}}">
    <input type="hidden" name="root_idx" value="{{result.id}}">
    <div>
        <span><strong>댓글</strong></span> <span id="cCnt"></span>
        <table class="table">
            <tr>
                <td><textarea rows="3" cols="110" id="comment" name="comment" playholder="댓글을 입력하세요."></textarea></td>
                <td><input type="submit" class="btn btn-success" style="height:80px;" value="등록하기"></td>
            </tr>
        </table>
    </div>
</form>

아래는 board_view 코드입니다.

@blueprint.route("/view/<idx>")
@login_required
def board_view(idx):
    if idx is not None:
        page = request.args.get("page") 
        search = request.args.get("search")
        keyword = request.args.get("keyword")


        board = mongo.db.board
        #data = board.find_one({"_id": ObjectId(idx)})
        data = board.find_one_and_update({"_id": ObjectId(idx)}, {"$inc": {"view": 1}}, return_document=True)

        if data is not None:
            result = {
                "id": data.get("_id"),
                "name": data.get("name"),
                "title": data.get("title"),
                "contents": data.get("contents"),
                "pubdate": data.get("pubdate"),
                "view": data.get("view"),
                "writer_id": data.get("writer_id", ""),
                "attachfile": data.get("attachfile", "")
            }

            return render_template("view.html", result=result, page=page, search=search, keyword=keyword, title="글상세보기")
    return abort(404)


그래서 board_view 부분을 바꿨는데요

@blueprint.route("/view")
@login_required
def board_view():
    idx = request.args.get("idx")
    if idx is not None:
        page = request.args.get("page") 
        search = request.args.get("search")
        keyword = request.args.get("keyword")


이런식으로요

그럼 이런 에러가 뜨네요

2022-09-01 22 59 43.png

답변 3

·

답변을 작성해보세요.

0

천승업님의 프로필

천승업

질문자

2022.09.03

자세히 찾아보니 오타가 있었네요.

수정하니까 정상작동 되는거 확인하였습니다.

0

천승업님의 프로필

천승업

질문자

2022.09.01

login_required 지우고 했는데도 똑같은 에러가 발생하네요..
6분44초 전까지는 다 잘 됐었는데..
다른 데서 로그인체크기능도 잘 작동하는데..



@blueprint.route("/comment_write", methods=["POST"])
def comment_write():
    if request.method == "POST":
        name = session.get("name")
        writer_id = session.get("id")
        root_idx = request.form.get("rood_idx")
        comment = request.form.get("comment")
        current_utc_time = round(datetime.utcnow().timestamp() * 1000)

        c_comment = mongo.db.comment

        post = {
            "root_idx": str(root_idx),
            "writer_id": writer_id,
            "name": name,
            "comment": comment,
            "pubdate": current_utc_time
        }
        
        c_comment.insert_one(post)
        return redirect(url_for("board.board_view", idx=root_idx))

BuildError

werkzeug.routing.exceptions.BuildError: Could not build url for endpoint 'board.board_view'. Did you forget to specify values ['idx']?

Traceback (most recent call last)

  • File "c:\Python\myweb\venv\lib\site-packages\flask\app.py", line 2091, in __call__

    return self.wsgi_app(environ, start_response)
  • File "c:\Python\myweb\venv\lib\site-packages\flask\app.py", line 2076, in wsgi_app

    response = self.handle_exception(e)
  • File "c:\Python\myweb\venv\lib\site-packages\flask\app.py", line 2073, in wsgi_app

    response = self.full_dispatch_request()
  • File "c:\Python\myweb\venv\lib\site-packages\flask\app.py", line 1519, in full_dispatch_request

    rv = self.handle_user_exception(e)
  • File "c:\Python\myweb\venv\lib\site-packages\flask\app.py", line 1517, in full_dispatch_request

    rv = self.dispatch_request()
  • File "c:\Python\myweb\venv\lib\site-packages\flask\app.py", line 1503, in dispatch_request

    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  • File "c:\Python\myweb\main\board.py", line 39, in comment_write

    return redirect(url_for("board.board_view", idx=root_idx))
  • File "c:\Python\myweb\venv\lib\site-packages\flask\helpers.py", line 336, in url_for

    return appctx.app.handle_url_build_error(error, endpoint, values)
  • File "c:\Python\myweb\venv\lib\site-packages\flask\helpers.py", line 323, in url_for

    rv = url_adapter.build(
  • File "c:\Python\myweb\venv\lib\site-packages\werkzeug\routing\map.py", line 917, in build

    raise BuildError(endpoint, values, method, self)

werkzeug.routing.exceptions.BuildError: Could not build url for endpoint 'board.board_view'. Did you forget to specify values ['idx']?

The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.

To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.

You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:

  • dump() shows all variables in the frame

  • dump(obj) dumps all that's known about the object

3333333333333.png

44444444444444444444444.png

0

웹사이트는 부분적인 코드만 봐서는 오류의 원인을 알수없습니다.

첫번째 오류는 아마도 데코레이터로 설정된 함수에서 발생하는 오류로 보입니다. login_required 로 데코레이터 된 함수를 확인해보셔야 할 듯 합니다.