인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

인프런 커뮤니티 질문&답변

연규양님의 프로필 이미지
연규양

작성한 질문수

파이썬 플라스크(Flask) 기반 웹 개발 및 업무 자동화 서비스 활용

Jinja2 템플릿 엔진 파악 - 연습문제 두번째

연습문제 풀이 질문입니다.

작성

·

218

0

구구단 출력 문제인데 질문이 있습니다.

main.py

from flask import Flask
from flask import render_template
from flask import redirect
from flask import request
from flask import url_for

app = Flask(__name__)

@app.route("/")
@app.route("/<int:num>", methods=['POST', 'GET'])
def gugudan(num=None):
    if request.method == 'GET':
        return render_template('index.html', gugudan=None)
    else:
        temp = request.form['input']
        return render_template('index.html', gugudan=temp)

if __name__ == "__main__":
    app.run(debug=True)

 

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='file.css') }}">
</head>
<body>
    <form action="/" method="POST">
        <p><input type="text"/ id="input" value="name"><input type="submit"></button></p>
    <form>

    {% if gugudan == None%}
        <p>Have to Type number</p>
    {% else %}
        <p>숫자가 입력되었습니다</p>
    {% endif %}
</body>
</html>

 

위와 같이 main.py에서 method 타입을 2가지로 나눠서 한번에 처리도 가능할거라 생각했는데, method not allowed가 나오네요.
혹시 무엇이 문제일까요?

 

답변

답변을 기다리고 있는 질문이에요
첫번째 답변을 남겨보세요!
연규양님의 프로필 이미지
연규양

작성한 질문수

질문하기