커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
4-12 localhost5001 사이트이용할 수 없음 나와요
undefined주차
북마크
정*성
댓글
3
추천
0
조회수
9
조회수
9
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.


index.html 을 찾을 수 없다고 하네요.



보고 계신 화면 전체를 캡처해 주시면, 튜터님들이


스파르타 즉문즉답스파르타 즉문즉답


빠르게 상황을 이해할 수 있어요.




작성한 코드 및 에러 메세지

  1. app.py
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)


@app.route('/')
def home():
    return render_template('index.html')


@app.route("/movie", methods=["POST"])
def movie_post():
    sample_receive = request.form['sample_give']
    print(sample_receive)
    return jsonify({'msg':'POST 연결 완료!'})


@app.route("/movie", methods=["GET"])
def movie_get():
    return jsonify({'msg':'GET 연결 완료!'})


if __name__ == '__main__':
    app.run('0.0.0.0', port=5001, debug=True)

2.index.html

<!doctype html>
<html lang="en">


<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">


    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
        crossorigin="anonymous"></script>


    <title>스파르타 피디아</title>


    <link href="https://fonts.googleapis.com/css2?family=Gowun+Dodum&display=swap" rel="stylesheet">


    <style>
        * {
            font-family: 'Gowun Dodum', sans-serif;
        }


        .mytitle {
            width: 100%;
            height: 250px;


            background-image: linear-gradient(0deg, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('https://movie-phinf.pstatic.net/20210715_95/1626338192428gTnJl_JPEG/movie_image.jpg');
            background-position: center;
            background-size: cover;


            color: white;


            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
        }


        .mytitle>button {
            width: 200px;
            height: 50px;


            background-color: transparent;
            color: white;


            border-radius: 50px;
            border: 1px solid white;


            margin-top: 10px;
        }


        .mytitle>button:hover {
            border: 2px solid white;
        }


        .mycomment {
            color: gray;
        }


        .mycards {
            margin: 20px auto 0px auto;
            width: 95%;
            max-width: 1200px;
        }


        .mypost {
            width: 95%;
            max-width: 500px;
            margin: 20px auto 0px auto;
            padding: 20px;
            box-shadow: 0px 0px 3px 0px gray;


            display: none;
        }


        .mybtns {
            display: flex;
            flex-direction: row;
            align-items: center;
            justify-content: center;


            margin-top: 20px;
        }


        .mybtns>button {
            margin-right: 10px;
        }
    </style>
    <script>
        $(document).ready(function () {
            listing();
        });


        function listing() {
            fetch('/movie').then((res) => res.json()).then((data) => {
                console.log(data)
                alert(data['msg'])
            })
        }


        function posting() {
            let formData = new FormData();
            formData.append("sample_give", "샘플데이터");


            fetch('/movie', { method: "POST", body: formData }).then((res) => res.json()).then((data) => {
                console.log(data)
                alert(data['msg'])
            })
        }


        function open_box() {
            $('#post-box').show()
        }
        function close_box() {
            $('#post-box').hide()
        }
    </script>
</head>


<body>
    <div class="mytitle">
        <h1>내 생애 최고의 영화들</h1>
        <button onclick="open_box()">영화 기록하기</button>
    </div>
    <div class="mypost" id="post-box">
        <div class="form-floating mb-3">
            <input id="url" type="email" class="form-control" placeholder="name@example.com">
            <label>영화URL</label>
        </div>
        <div class="form-floating">
            <textarea id="comment" class="form-control" placeholder="Leave a comment here"></textarea>
            <label for="floatingTextarea2">코멘트</label>
        </div>
        <div class="mybtns">
            <button onclick="posting()" type="button" class="btn btn-dark">기록하기</button>
            <button onclick="close_box()" type="button" class="btn btn-outline-dark">닫기</button>
        </div>
    </div>
    <div class="mycards">
        <div class="row row-cols-1 row-cols-md-4 g-4" id="cards-box">
            <div class="col">
                <div class="card h-100">
                    <img src="https://movie-phinf.pstatic.net/20210728_221/1627440327667GyoYj_JPEG/movie_image.jpg"
                        class="card-img-top">
                    <div class="card-body">
                        <h5 class="card-title">영화 제목이 들어갑니다</h5>
                        <p class="card-text">여기에 영화에 대한 설명이 들어갑니다.</p>
                        <p>⭐⭐⭐</p>
                        <p class="mycomment">나의 한줄 평을 씁니다</p>
                    </div>
                </div>
            </div>
            <div class="col">
                <div class="card h-100">
                    <img src="https://movie-phinf.pstatic.net/20210728_221/1627440327667GyoYj_JPEG/movie_image.jpg"
                        class="card-img-top">
                    <div class="card-body">
                        <h5 class="card-title">영화 제목이 들어갑니다</h5>
                        <p class="card-text">여기에 영화에 대한 설명이 들어갑니다.</p>
                        <p>⭐⭐⭐</p>
                        <p class="mycomment">나의 한줄 평을 씁니다</p>
                    </div>
                </div>
            </div>
            <div class="col">
                <div class="card h-100">
                    <img src="https://movie-phinf.pstatic.net/20210728_221/1627440327667GyoYj_JPEG/movie_image.jpg"
                        class="card-img-top">
                    <div class="card-body">
                        <h5 class="card-title">영화 제목이 들어갑니다</h5>
                        <p class="card-text">여기에 영화에 대한 설명이 들어갑니다.</p>
                        <p>⭐⭐⭐</p>
                        <p class="mycomment">나의 한줄 평을 씁니다</p>
                    </div>
                </div>
            </div>
            <div class="col">
                <div class="card h-100">
                    <img src="https://movie-phinf.pstatic.net/20210728_221/1627440327667GyoYj_JPEG/movie_image.jpg"
                        class="card-img-top">
                    <div class="card-body">
                        <h5 class="card-title">영화 제목이 들어갑니다</h5>
                        <p class="card-text">여기에 영화에 대한 설명이 들어갑니다.</p>
                        <p>⭐⭐⭐</p>
                        <p class="mycomment">나의 한줄 평을 씁니다</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>


</html>

3.meta_prac.py

import requests
from bs4 import BeautifulSoup


url = 'https://movie.naver.com/movie/bi/mi/basic.naver?code=191597'


headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'}
data = requests.get(url,headers=headers)


soup = BeautifulSoup(data.text, 'html.parser')


og_image = soup.select_one('meta[property="og:image"]')['content']
og_title = soup.select_one('meta[property="og:title"]')['content']
og_description = soup.select_one('meta[property="og:description"]')['content']


print(og_image,og_title,og_description)

오류 발생 시, 작성한 코드 전체와 에러 메시지를 첨부해 주세요.

/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/bin/python /Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/meta_prac.py
127.0.0.1 - - [22/Mar/2023 15:53:16] "GET / HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/flask/app.py", line 2551, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/flask/app.py", line 2531, in wsgi_app
    response = self.handle_exception(e)
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/flask/app.py", line 2528, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/flask/app.py", line 1825, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/flask/app.py", line 1823, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/app.py", line 6, in home
    return render_template('index.html')
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/flask/templating.py", line 146, in render_template
    template = app.jinja_env.get_or_select_template(template_name_or_list)
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/jinja2/environment.py", line 1081, in get_or_select_template
    return self.get_template(template_name_or_list, parent, globals)
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/jinja2/environment.py", line 1010, in get_template
    return self._load_template(name, globals)
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/jinja2/environment.py", line 969, in _load_template
    template = self.loader.load(self, name, self.make_globals(globals))
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/jinja2/loaders.py", line 126, in load
    source, filename, uptodate = self.get_source(environment, name)
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/flask/templating.py", line 62, in get_source
    return self._get_source_fast(environment, template)
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/flask/templating.py", line 98, in _get_source_fast
    raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: index.html
127.0.0.1 - - [22/Mar/2023 15:53:17] "GET / HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/flask/app.py", line 2551, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/flask/app.py", line 2531, in wsgi_app
    response = self.handle_exception(e)
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/flask/app.py", line 2528, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/flask/app.py", line 1825, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/flask/app.py", line 1823, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/app.py", line 6, in home
    return render_template('index.html')
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/flask/templating.py", line 146, in render_template
    template = app.jinja_env.get_or_select_template(template_name_or_list)
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/jinja2/environment.py", line 1081, in get_or_select_template
    return self.get_template(template_name_or_list, parent, globals)
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/jinja2/environment.py", line 1010, in get_template
    return self._load_template(name, globals)
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/jinja2/environment.py", line 969, in _load_template
    template = self.loader.load(self, name, self.make_globals(globals))
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/jinja2/loaders.py", line 126, in load
    source, filename, uptodate = self.get_source(environment, name)
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/flask/templating.py", line 62, in get_source
    return self._get_source_fast(environment, template)
  File "/Users/jeongjuseong/스파르타/웹개발/projects/03.pedia/venv/lib/python3.8/site-packages/flask/templating.py", line 98, in _get_source_fast
    raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: index.html
127.0.0.1 - - [22/Mar/2023 15:53:17] "GET /?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1" 304 -
127.0.0.1 - - [22/Mar/2023 15:53:17] "GET /?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1" 304 -
127.0.0.1 - - [22/Mar/2023 15:53:17] "GET /?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 304 -

Tip 1) </> 아이콘을 눌러 코드박스를 만들어 보세요.

Tip 2) Ctrl+A(맥의 경우 Command+A) 단축키로 코드를 한 번에 선택할 수 있어요!




취소
 공유
취소
댓글 0
댓글 알림
나의얼굴